As in image. for some values converting correctly but some of values not converting… you can see in image
I want to convert numbers to million.I am using Money format function to convert numbers but i am unable to convert numbers.
This is controller part.for some numbers it is converting to millions and for some numbers it is not converting.. Please someone help.
JavaScript
x
18
18
1
$scope.MoneyFormat = function (labelValue)
2
{
3
// Nine Zeroes for Billions
4
return Math.abs(Number(labelValue)) >= 1.0e+9
5
6
? Math.abs(Number(labelValue)) / 1.0e+9 + "B"
7
// Six Zeroes for Millions
8
: Math.abs(Number(labelValue)) >= 1.0e+6
9
10
? Math.abs(Number(labelValue)) / 1.0e+6 + "M"
11
// Three Zeroes for Thousands
12
: Math.abs(Number(labelValue)) >= 1.0e+3
13
14
? Math.abs(Number(labelValue)) / 1.0e+3 + "K"
15
16
: Math.abs(Number(labelValue));
17
}
18
Here I am converting numbers by using Moneyformat. This is controller part where I am converting numbers
JavaScript
1
6
1
$scope.rep.won = $scope.MoneyFormat($scope.rep.won);
2
$scope.outlook.rem = $scope.MoneyFormat($scope.outlook.rem);
3
$scope.rep.expectedAmount = $scope.MoneyFormat($scope.rep.expectedAmount);
4
$scope.rep.potential = $scope.MoneyFormat($scope.rep.potential);
5
$scope.rep.quota = $scope.MoneyFormat($scope.rep.quota);
6
Advertisement
Answer
I have no idea what $scope.MoneyFormat is.
So I simplified your function to a plain old js function and it works.
JavaScript
1
21
21
1
function convertToInternationalCurrencySystem (labelValue) {
2
3
// Nine Zeroes for Billions
4
return Math.abs(Number(labelValue)) >= 1.0e+9
5
6
? (Math.abs(Number(labelValue)) / 1.0e+9).toFixed(2) + "B"
7
// Six Zeroes for Millions
8
: Math.abs(Number(labelValue)) >= 1.0e+6
9
10
? (Math.abs(Number(labelValue)) / 1.0e+6).toFixed(2) + "M"
11
// Three Zeroes for Thousands
12
: Math.abs(Number(labelValue)) >= 1.0e+3
13
14
? (Math.abs(Number(labelValue)) / 1.0e+3).toFixed(2) + "K"
15
16
: Math.abs(Number(labelValue));
17
18
}
19
20
alert( convertToInternationalCurrencySystem (6800000) ); // this outputs 6.8M
21
JSFiddle: https://jsfiddle.net/r5ju34ey/