Example// This example demonstrates Math.Ceiling() // Math.Floor() using System;class Sample { public static void Main() { double value; string nl = Environment.NewLine;// Return the smallest whole number greater than or equal to the // specified number. // Note that the results are affected by the precision of the floating point // number, value. Console.WriteLine("{0}Ceiling:", nl); for (value = 0.0; value <= 1.1; value += 0.1) Console.WriteLine("Ceiling({0:f}) = {1}", value, Math.Ceiling(value));// Return the largest whole number less than or equal to the specified // number. // Note that the results are affected by the precision of the floating point // number, value. Console.WriteLine("{0}Floor:", nl); for (value = 2.1; value >= 0.9; value -= 0.1) 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) = 2Floor: 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) = 0 */
// Math.Floor()
using System;class Sample
{
public static void Main()
{
double value;
string nl = Environment.NewLine;// Return the smallest whole number greater than or equal to the
// specified number.
// Note that the results are affected by the precision of the floating point
// number, value. Console.WriteLine("{0}Ceiling:", nl);
for (value = 0.0; value <= 1.1; value += 0.1)
Console.WriteLine("Ceiling({0:f}) = {1}", value, Math.Ceiling(value));// Return the largest whole number less than or equal to the specified
// number.
// Note that the results are affected by the precision of the floating point
// number, value. Console.WriteLine("{0}Floor:", nl);
for (value = 2.1; value >= 0.9; value -= 0.1)
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) = 2Floor:
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) = 0
*/
Math 类 | Math 成员 | System 命名空间 | C++ 托管扩展编程
语言
C#C++JScriptVisual Basic全部显示
返回最接近指定值的数字。重载列表
返回最接近指定值的整数。受 .NET Framework 精简版的支持。[Visual Basic] Overloads Public Shared Function Round(Decimal) As Decimal
[C#] public static decimal Round(decimal);
[C++] public: static Decimal Round(Decimal);
[JScript] public static function Round(Decimal) : Decimal;
返回最接近指定值的整数。受 .NET Framework 精简版的支持。[Visual Basic] Overloads Public Shared Function Round(Double) As Double
[C#] public static double Round(double);
[C++] public: static double Round(double);
[JScript] public static function Round(double) : double;
返回具有指定精度、最接近指定值的数。受 .NET Framework 精简版的支持。[Visual Basic] Overloads Public Shared Function Round(Decimal, Integer) As Decimal
[C#] public static decimal Round(decimal, int);
[C++] public: static Decimal Round(Decimal, int);
[JScript] public static function Round(Decimal, int) : Decimal;
返回具有指定精度、最接近指定值的数。受 .NET Framework 精简版的支持。[Visual Basic] Overloads Public Shared Function Round(Double, Integer) As Double
[C#] public static double Round(double, int);
[C++] public: static double Round(double, int);
[JScript] public static function Round(double, int) : double;
示例
下面的代码演示就近舍入。[Visual Basic]
Math.Round(3.44, 1) 'Returns 3.4.
Math.Round(3.45, 1) 'Returns 3.4.
Math.Round(3.46, 1) 'Returns 3.5.[C#]
Math.Round(3.44, 1); //Returns 3.4.
Math.Round(3.45, 1); //Returns 3.4.
Math.Round(3.46, 1); //Returns 3.5.[C++] Math::Round(3.44, 1); //Returns 3.4.
Math::Round(3.45, 1); //Returns 3.4.
Math::Round(3.46, 1); //Returns 3.5.[JScript]
System.Math.Round(3.44, 1) //Returns 3.4.
System.Math.Round(3.45, 1) //Returns 3.4.
System.Math.Round(3.46, 1) //Returns 3.5.请参见
Math 类 | Math 成员 | System 命名空间 | C++ 托管扩展编程
--------------------------------------------------------------------------------发送有关此主题的意见 © 2001-2002 Microsoft Corporation。保留所有权利。