使用AngularJS将数字限制为HTML文件中的2位小数 [英] Restricting number to 2 decimal places in HTML file with AngularJS

查看:717
本文介绍了使用AngularJS将数字限制为HTML文件中的2位小数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个HTML页面显示AngularJS控制器的信息。这是代码的一部分:

I have a HTML page that displays the information from an AngularJS controller. This is part of the code:

<td id="calories">{{ ctrl.caltotal }}</td>

我的问题是,我需要做什么,以显示最大值为十进制地方?目前,如果我改变程序,它可以给出像23.00000004的值。这是一个应该在Angular Controller或HTMl视图中进行的更改吗?感谢。

My question is, what do I need to do so that this is displayed at a maximum of 2 decimal places? At the moment if I change the program it can give values like 23.00000004. Is this a change that should be made in the Angular Controller or in the HTMl view? Thanks.

推荐答案

<td id="calories">{{ ctrl.caltotal | number:2}}</td>

这将限制为两位小数。

这篇关于使用AngularJS将数字限制为HTML文件中的2位小数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆