' '自己写个四舍五入 ' Dim c As Double = 15.2321215 Dim f As Integer If (c <> Fix(c)) Then Dim d As String = c.ToString.Substring(c.ToString.IndexOf(".")) If Val("0" & d) >= 0.5 Then f = Fix(c) + 1 Else f = Fix(c) End If Else f = Fix(c) End If Return f.ToString()
'自己写个四舍五入
'
Dim c As Double = 15.2321215
Dim f As Integer
If (c <> Fix(c)) Then
Dim d As String = c.ToString.Substring(c.ToString.IndexOf("."))
If Val("0" & d) >= 0.5 Then
f = Fix(c) + 1
Else
f = Fix(c)
End If
Else
f = Fix(c)
End If
Return f.ToString()
float f1 = 15.23;
string strValue = f1.ToString( "f1" );//strValue: 15.2
f1 = 15.25;
string strValue = f1.ToString( "f1" );//strValue: 15.3