PowerShell Round和Format Float最多2位小数?

前端之家收集整理的这篇文章主要介绍了PowerShell Round和Format Float最多2位小数?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我发现很多东西可以将浮点数格式化为常见的已知数字,
但是如何将浮点数格式化为最多2位小数,但只有在需要小数的情况下?

例子:

@H_301_5@1.11 # not 1.111 1.12 # it was 1.116 (round up) 1.1 # not 1.10 1 # not 1.00

如果我做

@H_301_5@$('{0:N2}' -f $flt)

我明白了

@H_301_5@1.00 # :(

提前致谢!

解决方法

使用[math] :: round,即: @H_301_5@[math]::round(1.111,2)

将返回1.11和

@H_301_5@[math]::round(1.00,2)

收益率1

猜你在找的CSS相关文章