Adds watcher for changes to value or currency scope variables

This commit is contained in:
Sam Cheng Hung 2018-07-31 16:23:45 +08:00
commit 1895e0dbeb

View file

@ -48,37 +48,44 @@ angular.module('bitcoincom.directives')
return '2'; return '2';
}; };
switch (getDecimalPlaces($scope.currency)) { var formatNumbers = function(currency, value) {
case '0': switch (getDecimalPlaces(currency)) {
var valueFormatted = numberWithCommas(Math.round(parseFloat($scope.value))); case '0':
buildAmount(valueFormatted, '', ''); var valueFormatted = numberWithCommas(Math.round(parseFloat(value)));
break;
case '2':
var valueProcessing = parseFloat(parseFloat($scope.value).toFixed(2));
var valueFormatted = numberWithCommas(valueProcessing);
buildAmount(valueFormatted, '', '');
break;
case '3':
var valueProcessing = parseFloat(parseFloat($scope.value).toFixed(3));
var valueFormatted = numberWithCommas(valueProcessing);
buildAmount(valueFormatted, '', '');
break;
case '8':
var valueFormatted = parseFloat($scope.value).toFixed(8);
if (parseFloat($scope.value) == 0) {
buildAmount('0', '', '');
} else {
buildAmount(valueFormatted, '', ''); buildAmount(valueFormatted, '', '');
var start = numberWithCommas(valueFormatted.slice(0, -5)); break;
var middle = valueFormatted.slice(-5, -2);
var end = valueFormatted.substr(valueFormatted.length - 2); case '2':
buildAmount(start, middle, end); var valueProcessing = parseFloat(parseFloat(value).toFixed(2));
} var valueFormatted = numberWithCommas(valueProcessing);
break; buildAmount(valueFormatted, '', '');
break;
case '3':
var valueProcessing = parseFloat(parseFloat(value).toFixed(3));
var valueFormatted = numberWithCommas(valueProcessing);
buildAmount(valueFormatted, '', '');
break;
case '8':
var valueFormatted = parseFloat(value).toFixed(8);
if (parseFloat(value) == 0) {
buildAmount('0', '', '');
} else {
buildAmount(valueFormatted, '', '');
var start = numberWithCommas(valueFormatted.slice(0, -5));
var middle = valueFormatted.slice(-5, -2);
var end = valueFormatted.substr(valueFormatted.length - 2);
buildAmount(start, middle, end);
}
break;
}
} }
formatNumbers($scope.currency, $scope.value);
$scope.$watchGroup(['currency', 'value'], function() {
formatNumbers($scope.currency, $scope.value);
});
}] }]
}; };
} }