简体   繁体   中英

Convert decimal point number to integer - PowerShell

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)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM