所以我有一个123.778967的双倍。我希望它以123.7的形式返回。 我读过和尝试过的所有东西都是圆形的,所以我得到了123.8因为它正在四舍五入。那么有人能告诉我如何削减我不想要的数字吗?
答案 0 :(得分:2)
我之前用它作为扩展方法:
''' <summary>
''' Truncate the provided decimal value to the provided number of decimal places.
''' </summary>
''' <param name="ToTruncate">The number to be truncated.</param>
''' <param name="NumberOfPlaces">The number of decimal places at which the number will be truncated.</param>
''' <returns>The provided number, truncated to the provided number of decimal places.</returns>
''' <remarks></remarks>
<System.Runtime.CompilerServices.Extension()>
Function TruncateDecimal(ByVal toTruncate As Decimal, ByVal numberOfPlaces As Integer) As Decimal
Dim temp = (10 ^ numberOfPlaces)
Return CDec(Fix(toTruncate * temp) / temp)
End Function