Search code examples
powershellrounding

Rounding up a double to the nearest integer


How can I convert a double to an int but make sure it rounds up regardless of the decimal value (as long as decimal value is not 0)?


Solution

  • You can use the .NET [Math]::Ceiling function and cast the result to [int]:

    PS > [int][Math]::Ceiling(1.1)
    2   
    PS > [int][Math]::Ceiling(1.6)
    2
    PS >