你知道返回多少吗?(使用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的整数。 
作者:Jackhuclan
出处:http://jackhuclan.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
原文地址:https://www.cnblogs.com/jackhuclan/p/877732.html