powershell - Powershell-数字格式显示错误的结果

标签 powershell formatting numbers powershell-2.0

在powershell v2中,我需要将22除以8,然后除去小数点后的所有小数位(在我的系统上为逗号)。没有舍入。

如你所见。 22/8等于 2,75

PS C:\ Documents and Settings \ Administrator> $(22/8)
2,75

预期结果为 2

奇怪的是,使用不同的方法计算相同的结果时,会得到不同的结果。

PS C:\ Documents and Settings \ Administrator>“{0:N0}” -f $(22/8)
3

PS C:\ Documents and Settings \ Administrator>“{0:N0}” -f 2.75
3

PS C:\ Documents and Settings \ Administrator>“{0:N0}” -f 2,75
2

其他一些例子...

PS C:\ Documents and Settings \ Administrator>“{0:N0}” -f 2.15
2

PS C:\ Documents and Settings \ Administrator>“{0:N0}” -f 2,15
2

原因是什么?

最佳答案

这对您有用吗?

[math]::Floor(22/8)

结果: 2

关于powershell - Powershell-数字格式显示错误的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8648999/

相关文章:

algorithm - 计算正整数幂的最快算法是什么?

Javascript正则表达式匹配以数字结尾的字符串不一致

Powershell Windows 2003 通配符不起作用

powershell - 如何修改%username%\AppData中的文件

powershell - Powershell get-Itemm VersionInfo.ProductVersion错误/与WMI不同

Delphi 自动 Format Source 破坏匿名程序

ruby-on-rails - Ruby on Rails 的 BBCode

r - 如何格式化 Shiny 的渲染表?

c++ - 做一个有潜在溢出的乘法然后用除法验证有什么问题吗?

powershell - Powershell/批处理网络映射驱动器