如果我Math.Round(95.55555555,2)在VB.NET中,结果是95.56,但我想要它的结果95.55.有没有办法在VB.NET中执行此操作?我想我只是想保留小数位,但不要围绕它们
尝试使用 Math.Floor(95.55555555 * 100) / 100
或者,如果要舍入到特定的小数位数:
Public Function RoundDown(ByVal value As Double, ByVal decimalPlaces As Integer) As Double
If (decimalPlaces < 1) Then
Throw New ArgumentException("Invalid decimalPlaces: less than 1")
EndIf
Dim factor As Integer = 10 ^ decimalPlaces
Return Math.Floor(value * factor) / factor
End Sub
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
30941 次 |
| 最近记录: |