Exportar (0) Imprimir
Expandir todo

Math.Floor (Método) (Double)

Devuelve el entero más grande mayor o igual que el número de punto flotante de precisión doble especificado.

Espacio de nombres: System
Ensamblado: mscorlib (en mscorlib.dll)

public static double Floor (
	double d
)
public static double Floor (
	double d
)
public static function Floor (
	d : double
) : double

Parámetros

d

Número de punto flotante de precisión doble.

Valor devuelto

Número entero más grande menor o igual que d. Si d es igual a NaN, NegativeInfinity o PositiveInfinity, se devuelve ese valor.

El comportamiento de este método sigue el estándar IEEE 754, sección 4. A este tipo de redondeo a veces se le denomina redondeo hacia el infinito negativo.

En el ejemplo de código siguiente se muestran los métodos Ceiling y Floor.

// 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
*/

// This example demonstrates Math.Ceiling()
//                           Math.Floor()
import System.*;

class Sample
{
    public static void main(String[] args)
    {
        double value;
        double idx;
        String nl = Environment.get_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.0; idx <= 1.1; idx += 0.1) {
            //ToDo: Unsupported feature: assignment within expression
            value = Convert.ToDouble(idx);
            Console.WriteLine("Ceiling({0:f}) = {1}", (System.Double)value, 
                (System.Double)System.Math.Ceiling(value));
        }
        // Return the largest whole number less than or equal to 
        // the specified number.
        Console.WriteLine("{0}Floor:", nl);
        for (idx = 2.1; idx >= 1.0; idx -= 0.1) {
            //ToDo: Unsupported feature: assignment within expression
            value = Convert.ToDouble(idx);
            Console.WriteLine("Floor({0:f})   = {1}", (System.Double)value, 
                (System.Double)System.Math.Floor(value));
        }
    } //main
} //Sample
/*

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
*/

Windows 98, Windows 2000 SP4, Windows Millennium, Windows Server 2003, Windows XP Media Center, Windows XP Professional x64, Windows XP SP2, Windows XP Starter Edition

.NET Framework no admite todas las versiones de cada plataforma. Para obtener una lista de las versiones admitidas, vea Requisitos del sistema.

.NET Framework

Compatible con: 2.0, 1.1, 1.0

.NET Compact Framework

Compatible con: 2.0, 1.0

Adiciones de comunidad

AGREGAR
Mostrar:
© 2014 Microsoft