Angular noob here! I am trying to display a percentage value in my html as follows:
<td> {{ ((myvalue/totalvalue)*100) }}%</td>
It works but sometimes it gives a very long decimal which looks weird. How do i round it off to 2 digits after the decimal? Is there a better approach to this?
The discount is the original price minus the sale price, so your equation should be ((product. price - product. newprice)/product. price)*100 .
Divide the smaller portion's area by the whole piece's area. For example, 40 / 160 = . 25. Therefore, the area of the smaller portion is 25 percent of the area of the original piece.
You could use a filter, like this one below by jeffjohnson9046
The filter makes the assumption that the input will be in decimal form (i.e. 17% is 0.17).
myApp.filter('percentage', ['$filter', function ($filter) {
return function (input, decimals) {
return $filter('number')(input * 100, decimals) + '%';
};
}]);
Usage:
<tr ng-repeat="i in items">
<td>{{i.statistic | percentage:2}}</td>
</tr>
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