我正在用離子和Firebase構建一個應用程序。我有數字有時有小數,我想截斷它們爲整數。如何將數組的結果轉換爲Int?
這裏是我的代碼:
var visitMaster = [0, 0, 0, 0, 0, 0, 0];
$timeout(function(){
var visitRef = firebase.database().ref('/business/' + myId + '/visits/');
// LAST HOUR
visitRef.orderByChild("visit").startAt(nowMinusOne).endAt(now).once("value", function(snapshot) {
var visitOneHour = (snapshot.numChildren()/2);
if (visitOneHour === ""){
visitMaster.splice(6, 1, 0);
} else {
visitMaster.splice(6, 1, visitOneHour);
}
});
如何呈現這些數字在我visitMaster爲INT?
UPDATE:陣列的每個值應該去的圖表(巴)在,所以我顯示這種方式:
//WE PUT IT IN THE CHART:
$scope.labels = ["H-6", "H-5", "H-4", "H-3", "H-2", "H-1", "Now"];
$scope.data = [
visitMaster,
];
我想每個值是一個整數(最他們中有十.5)
[如何小數轉換爲整數的一個問題已經在這裏找到答案(http://stackoverflow.com/questions/596467/how-do-i-convert-a- float-number-to-a-whole-number-in-javascript) –
vistMaster.map(Number)也許? –
您是否試圖從數組中總計總值? – fubar