I am writing a PowerShell script that converts a number with a decimal point into an integer.
$val = 1024.24
How to convert this value to integer? (I want it to be 1024)
CodePudding user response:
Use floor rounding, which rounds to the lower whole number
[Math]::Floor($val)
Edit: if just discarding decimal part is not what you are looking for you can use [Math]::Round($val)
which will round the number like normal math rounding or you can use [Math]::Ceiling($val)
which will round up (in your case it will round to 1025) and it is probably not what you need but it is good to know that you have these options as well.