Math.Ceiling Method (Double)

.NET Framework Class Library
Math.Ceiling Method (Double)

Returns the smallest integer greater than or equal to the specified double-precision floating-point number. 

C#
public static double Ceiling (
    double a
)
Parameters
a

A double-precision floating-point number.

 

 

Return Value
The smallest integer greater than or equal to a. If a is equal to NaN, NegativeInfinity, or PositiveInfinity, that value is returned.
// This example demonstrates Math.Ceiling()
//                           Math.Floor()
using System;
class Sample
{
    public static void Main()
    {
    double value;
    decimal idx;
    string nl = Environment.NewLine;
// Return the smallest whole number greater than or equal to the specified number.
// Note that the floating point parameter used in the Math members should not also 
// be used as the loop index. The reason is the loop will not terminate as expected
// because a floating point number only approximates a decimal number. 
// For the sake of generalizing this example, the decimal index is converted to a 
// floating point number with the Convert class instead of a programming language-
// specific type conversion.
    Console.WriteLine("{0}Ceiling:", nl);
    for (idx = 0.0m; idx <= 1.1m; idx += 0.1m)
        {
        value = Convert.ToDouble(idx);
        Console.WriteLine("Ceiling({0:f}) = {1}", value, Math.Ceiling(value));
        }
// Return the largest whole number less than or equal to the specified number.
    Console.WriteLine("{0}Floor:", nl);
    for (idx = 2.1m; idx >= 1.0m; idx -= 0.1m)
        {
        value = Convert.ToDouble(idx);
        Console.WriteLine("Floor({0:f})   = {1}", value, Math.Floor(value));
        }
    }
}
/*
This example produces the following results:
Ceiling:
Ceiling(0.00) = 0
Ceiling(0.10) = 1
Ceiling(0.20) = 1
Ceiling(0.30) = 1
Ceiling(0.40) = 1
Ceiling(0.50) = 1
Ceiling(0.60) = 1
Ceiling(0.70) = 1
Ceiling(0.80) = 1
Ceiling(0.90) = 1
Ceiling(1.00) = 1
Ceiling(1.10) = 2
Floor:
Floor(2.10)   = 2
Floor(2.00)   = 2
Floor(1.90)   = 1
Floor(1.80)   = 1
Floor(1.70)   = 1
Floor(1.60)   = 1
Floor(1.50)   = 1
Floor(1.40)   = 1
Floor(1.30)   = 1
Floor(1.20)   = 1
Floor(1.10)   = 1
Floor(1.00)   = 1
*/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值