I am using the following code to try and roundup in Angular, which on the whole works, however numbers less than 0.5 are rounded to 0. I would like to round up every number to the next whole number. E.g 0.02 should be rounded to 1
{{((data.Virtual.SumCores/data.Physical.SumCores) | number:0)*1}}
The Math. round() method rounds a number to the nearest integer. 2.49 will be rounded down (2), and 2.5 will be rounded up (3).
ceil() The Math. ceil() function always rounds up and returns the smaller integer greater than or equal to a given number.
AngularJS is a structural framework for dynamic web apps. It lets you use HTML as your template language and lets you extend HTML's syntax to express your application's components clearly and succinctly. AngularJS's data binding and dependency injection eliminate much of the code you would otherwise have to write.
Use this
Math.ceil(4.4); //Returns 5
Math.ceil(0.002); //Returns 1
The filter
.filter('roundup', function () {
return function (value) {
return Math.ceil(value);
};
})
The HTML
{{ yourdata | roundup }}
reference
JS Math
You can create a filter for this:
.filter('roundup', function() {
return function(input) {
return Math.ceil(input);
};
});
And use it like this:
{{ data.Virtual.SumCores/data.Physical.SumCores | roundup }}
Since all of the answers are based on Math.ceil() function, you can simply add
$scope.Math=window.Math;
into your controller and use it like this:
{{ Math.ceil(data.Virtual.SumCores/data.Physical.SumCores) }}
This way you get the access to all Math functions.
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