在HTML角计算百分比 [英] Angular calculate percentage in the html

查看:347
本文介绍了在HTML角计算百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面角小白!我想在我的HTML中显示的百分比值如下:

Angular noob here! I am trying to display a percentage value in my html as follows:

<td> {{ ((myvalue/totalvalue)*100) }}%</td>

它的工作原理,但有时它给出了一个很长的小数,看起来怪怪的。我如何圆其关闭,以2位数小数点后?有没有更好的办法呢?

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?

推荐答案

您可以使用 toFixed 数的方法

((myValue/totalValue)*100).toFixed(2)

这篇关于在HTML角计算百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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