你知道返回多少吗?(使用Math类)

using System;

public class Demo17
{
    
public static void Main()
    
{
        
double d=3.5;
        
        Console.WriteLine(Math.Floor(d));
        
        Console.WriteLine(Math.Truncate(d));
        
        Console.WriteLine(Math.Round(d));
        
        d
=-d;
        
        Console.WriteLine(Math.Floor(d));
        
        Console.WriteLine(Math.Truncate(d));
        
        Console.WriteLine(Math.Round(d));
    }

}


知道返回结果吗?
3
3
 4
 -4
 -3
 -4

结论:Floor返回小于或等于指定数字的最大整数,Round返回最接近指定值的数字(四舍五入),
Truncate返回数字的整数部分,它会将数字舍入成最接近0的整数。 
posted @ 2007-08-31 20:37  落叶潇潇雨  阅读(289)  评论(1编辑  收藏  举报