public class DoubleCovertToInt小数取整
{
public void testEveryConvert()
{
Console.WriteLine("测试用数字:n3.15,3.45,3.5,3.55,3.65,3.75,3.85,3.95,4.0,-3.15, -3.45, -3.5, -3.55 -3.95, -4.0");
double[] testNum = { 3.15,3.45,3.5,3.55, 3.65, 3.75, 3.85, 3.95, 4.0 ,-3.15, -3.45, -3.5, -3.55, -3.95, -4.0};
Console.WriteLine("Math.Floor()舍去小数取整,取小于等于当前数据的最小整数");
foreach (var f in testNum)
{
Console.Write(Math.Floor(f) + " ");
}
Console.WriteLine();
Console.WriteLine("Math.Round()
四舍五入取整,中间取偶数");
foreach (var r in testNum)
{ // www.jb200.com
Console.Write(Math.Round(r) + " ");
}
Console.WriteLine();
Console.WriteLine("Math.Ceiling()凑整,取大于等于当前数据的最小整数");
foreach (var c in testNum)
{
Console.Write(Math.Ceiling(c) + " ");
}
Console.WriteLine();
Console.WriteLine("Truncate()截取,舍去小数部分");
foreach (var t in testNum)
{
Console.Write(Math.Truncate(t) + " ");
}
Console.WriteLine();
Console.ReadLine();
}