Powershell - Round down to nearest whole number

后端 未结 4 994
無奈伤痛
無奈伤痛 2021-02-05 02:20

What\'s the best way to round down to nearest whole number in Powershell?

I am trying [math]::truncate but its not giving me predictable results.

Example:

<
4条回答
  •  孤街浪徒
    2021-02-05 03:04

    Ah, I see. Looks like the datatype needs to be decimal:

    [decimal] $de = 17.2/.1
    [double] $db = 17.2/.1
    
    [math]::floor($de)
    172
    [math]::floor($db)
    171
    

    http://msdn.microsoft.com/en-us/library/system.math.floor(v=vs.85).aspx

提交回复
热议问题