[数値の切り上げ]
数値を指定した桁で切り上げます。
【ソースコード】
[tips0012.vbs]
Option Explicit
Function RoundUp(ByVal dblValue, ByVal lngDigit)
RoundUp = Fix((dblValue + (9 * (10 ^ (-1 * (lngDigit + 1))))) * (10 ^ lngDigit)) / (10 ^ lngDigit)
End Function
Dim dblValue
dblValue = 12345.67890
WScript.Echo dblValue & " を各桁で切り上げ"
WScript.Echo " " & RoundUp(12345.67890, 2)
WScript.Echo " " & RoundUp(12345.67890, 1)
WScript.Echo " " & RoundUp(12345.67890, 0)
WScript.Echo " " & RoundUp(12345.67890, -1)
WScript.Echo " " & RoundUp(12345.67890, -2)
【実行結果】
C:\> cscript //NoLogo tips0012.vbs
12345.6789 を各桁で切り上げ
12345.68
12345.7
12346
12350
12400