对于像 (25) 这样带有角度百分比管道的数字,限制为 2 位小数

问题描述 投票:0回答:2

我想用角度百分比管将数字转换为百分比格式,例如 25 到 25.00%。我用过这个。

{{ number | percent : '0.2-2'}}

我的成绩是 2,500.00%。有人可以帮我吗?

javascript angular pipe
2个回答
2
投票

您可能正在使用一个大数字,请在 stackblitz 上查看此示例。请记住,

1
等于
100%
,因此要显示
25%
,您需要输入
0.25

另外,检查文档及其示例,应该是毫无疑问的

https://stackblitz.com/edit/angular-ivy-iszurj?file=src%2Fapp%2Fapp.component.html

https://angular.io/api/common/PercentPipe


0
投票

请将数字除以100,然后你将得到想要的输出

输入 数量 = 25;

{{ 数量/100 |百分比:'0.2'}}

输出将是 25.00%

© www.soinside.com 2019 - 2024. All rights reserved.