前端之家收集整理的这篇文章主要介绍了
vb.net 四舍五入方法,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Module Module1
Sub Main()
Dim d1,d2,d3 As Double
d1 = 1.234
d2 = 1.345
d3 = 1.456
'-----------------------四舍六入-----------------------------
Console.Write("Result of Round(" & d1 & ") is : ")
Console.WriteLine(Math.Round(d1,2))
Console.Write("Result of Round(" & d2 & ") is : ")
Console.WriteLine(Math.Round(d2,2))
Console.Write("Result of Round(" & d3 & ") is : ")
Console.WriteLine(Math.Round(d3,2))
'----------------------四舍五入------------------------------
Console.Write("Result of Format(" & d1 & ") is : ")
Console.WriteLine(d1.ToString("0.00"))
Console.Write("Result of Format(" & d2 & ") is : ")
Console.WriteLine(d2.ToString("0.00"))
Console.Write("Result of Format(" & d3 & ") is : ")
Console.WriteLine(d3.ToString("0.00"))
'-----------------------去尾-----------------------------
Console.Write("Result of Floor(" & d1 & ") is : ")
Console.WriteLine(Math.Floor(d1 * 100) / 100)
Console.Write("Result of Floor(" & d2 & ") is : ")
Console.WriteLine(Math.Floor(d2 * 100) / 100)
Console.Write("Result of Floor(" & d3 & ") is : ")
Console.WriteLine(Math.Floor(d3 * 100) / 100)
'----------------------进一------------------------------
Console.Write("Result of Ceiling(" & d1 & ") is : ")
Console.WriteLine(Math.Ceiling(d1 * 100) / 100)
Console.Write("Result of Ceiling(" & d2 & ") is : ")
Console.WriteLine(Math.Ceiling(d2 * 100) / 100)
Console.Write("Result of Ceiling(" & d3 & ") is : ")
Console.WriteLine(Math.Ceiling(d3 * 100) / 100)
Console.Read()
End Sub
End Module
Module Module1 Sub Main() Dim d1,d3 As Double d1 = 1.234 d2 = 1.345 d3 = 1.456 '-----------------------四舍六入----------------------------- Console.Write("Result of Round(" & d1 & ") is : ") Console.WriteLine(Math.Round(d1,2)) Console.Write("Result of Round(" & d2 & ") is : ") Console.WriteLine(Math.Round(d2,2)) Console.Write("Result of Round(" & d3 & ") is : ") Console.WriteLine(Math.Round(d3,2)) '----------------------四舍五入------------------------------ Console.Write("Result of Format(" & d1 & ") is : ") Console.WriteLine(d1.ToString("0.00")) Console.Write("Result of Format(" & d2 & ") is : ") Console.WriteLine(d2.ToString("0.00")) Console.Write("Result of Format(" & d3 & ") is : ") Console.WriteLine(d3.ToString("0.00")) '-----------------------去尾----------------------------- Console.Write("Result of Floor(" & d1 & ") is : ") Console.WriteLine(Math.Floor(d1 * 100) / 100) Console.Write("Result of Floor(" & d2 & ") is : ") Console.WriteLine(Math.Floor(d2 * 100) / 100) Console.Write("Result of Floor(" & d3 & ") is : ") Console.WriteLine(Math.Floor(d3 * 100) / 100) '----------------------进一------------------------------ Console.Write("Result of Ceiling(" & d1 & ") is : ") Console.WriteLine(Math.Ceiling(d1 * 100) / 100) Console.Write("Result of Ceiling(" & d2 & ") is : ") Console.WriteLine(Math.Ceiling(d2 * 100) / 100) Console.Write("Result of Ceiling(" & d3 & ") is : ") Console.WriteLine(Math.Ceiling(d3 * 100) / 100) Console.Read() End Sub End Module
原文链接:https://www.f2er.com/vb/259315.html