Math functions in AngularJS bindings

后端 未结 13 1163
无人及你
无人及你 2020-11-29 17:55

Is there a way to use math functions in AngularJS bindings?

e.g.

The percentage is {{Math.round(100*count/total)}}%

13条回答
  •  失恋的感觉
    2020-11-29 18:26

    While the accepted answer is right that you can inject Math to use it in angular, for this particular problem, the more conventional/angular way is the number filter:

    The percentage is {{(100*count/total)| number:0}}%

    You can read more about the number filter here: http://docs.angularjs.org/api/ng/filter/number

提交回复
热议问题