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
You can use JavaScript supported built-in Math object for getting absolute value.
Math.abs(-2.34)
The Math.abs() function returns the absolute value of a number
Reference
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With