powershell - 将整数 x.xxxxx 格式化为 xx.xxx

我有一个号码,$int,

$int = 9.5587452369

我希望这个数字采用 xx.xxx 格式 我试过了:

$int = "{0:N3}" -f ($int)
$int = "{0:D2}" -f ($int)

$int = "{0:D2}" -f ("{0:N3}" -f ($int))

但它不起作用。有什么想法吗?

最佳答案

使用指定格式的toString()方法。

PS > $int = 9.5587452369
PS > $int.ToString("00.000")
09,559

或者

PS > "{0:00.000}" -f $int
09,559 

更多信息请访问 MSDN - Custom Numeric Format Strings

https://stackoverflow.com/questions/14802963/

相关文章:

excel - 条件格式 : making cells colorful

python - Python中的十进制对齐格式

excel - Vba检查单元格中是否部分粗体

c# - Visual Studio/ReSharper 代码格式化 - C#

io - 使用英特尔 Fortran 编译器避免列表导向输出中的换行符

python - 是否可以使用 weasyprint 对页脚进行精美的格式化?

python - 在 Python Pandas DataFrame 或 Jupyter Noteb

mysql - MySQL中的字符串格式化

java - 将 lenient 设置为 false 时的 SimpleDateFormat 异常

c# - 解释令人困惑的条件字符串格式