I am getting a negative number from JSON object. I want to remove "-" form that negative number and only display the absolute value.
Received json:
{
"value": -2.34
}
What I want to show:
The value is: 2.34
I am getting a negative number from JSON object. I want to remove "-" form that negative number and only display the absolute value.
Received json:
{
"value": -2.34
}
What I want to show:
The value is: 2.34
You can use angular filter
js file
angular.module('myApp',[]).filter('makePositive', function() {
return function(num) { return Math.abs(num); }
});
html file
{{ (-12) | makePositive }}
{{ (2) | makePositive }}
output
12 2
Math.abs(number)
This will get you the absolute value of any number you put in there, including the removal of any leading zeroes.
Additionally, you can also do this:
parseInt(number, 10)