Decimal.Floor(Decimal) Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Arrondit un nombre spécifié Decimal à l’entier le plus proche vers l’infini négatif.
public:
static System::Decimal Floor(System::Decimal d);
public:
static System::Decimal Floor(System::Decimal d) = System::Numerics::IFloatingPoint<System::Decimal>::Floor;
public static decimal Floor(decimal d);
static member Floor : decimal -> decimal
Public Shared Function Floor (d As Decimal) As Decimal
Paramètres
- d
- Decimal
Valeur à arrondir.
Retours
Si d elle a une partie fractionnaire, le prochain nombre entier Decimal vers l’infini négatif qui est inférieur à d.
- ou -
Si d elle n’a pas de partie fractionnaire, d elle est retournée inchangée. Notez que la méthode retourne une valeur intégrale de type Decimal.
Implémente
Exemples
L’exemple suivant illustre la Floor méthode et la contraste avec la Ceiling méthode.
using System;
public class Example
{
public static void Main()
{
decimal[] values = {12.6m, 12.1m, 9.5m, 8.16m, .1m, -.1m, -1.1m,
-1.9m, -3.9m};
Console.WriteLine("{0,-8} {1,10} {2,10}\n",
"Value", "Ceiling", "Floor");
foreach (decimal value in values)
Console.WriteLine("{0,-8} {1,10} {2,10}", value,
Decimal.Ceiling(value), Decimal.Floor(value));
}
}
// The example displays the following output:
// Value Ceiling Floor
//
// 12.6 13 12
// 12.1 13 12
// 9.5 10 9
// 8.16 9 8
// 0.1 1 0
// -0.1 0 -1
// -1.1 -1 -2
// -1.9 -1 -2
// -3.9 -3 -4
open System
let values =
[ 12.6m; 12.1m; 9.5m; 8.16m; 0.1m; -0.1m; -1.1m; -1.9m; -3.9m ]
printfn "%-8s %10s %10s\n" "Value" "Ceiling" "Floor"
for value in values do
printfn $"%-8O{value} %10O{Decimal.Ceiling value} %10O{Decimal.Floor value}"
// The example displays the following output:
// Value Ceiling Floor
//
// 12.6 13 12
// 12.1 13 12
// 9.5 10 9
// 8.16 9 8
// 0.1 1 0
// -0.1 0 -1
// -1.1 -1 -2
// -1.9 -1 -2
// -3.9 -3 -4
Module Example
Public Sub Main()
Dim values() As Decimal = {12.6d, 12.1d, 9.5d, 8.16d, .1d, -.1d,
-1.1d, -1.9d, -3.9d}
Console.WriteLine("{0,-8} {1,10} {2,10}",
"Value", "Ceiling", "Floor")
Console.WriteLine()
For Each value As Decimal In values
Console.WriteLine("{0,-8} {1,10} {2,10}", value,
Decimal.Ceiling(value), Decimal.Floor(value))
Next
End Sub
End Module
' The example displays the following output:
' Value Ceiling Floor
'
' 12.6 13 12
' 12.1 13 12
' 9.5 10 9
' 8.16 9 8
' 0.1 1 0
' -0.1 0 -1
' -1.1 -1 -2
' -1.9 -1 -2
' -3.9 -3 -4
Remarques
Le comportement de cette méthode suit IEEE Standard 754, Section 4. Ce type d’arrondi est parfois appelé arrondi vers l’infini négatif. En d’autres termes, s’il d est positif, tout composant fractionnaire est tronqué. Si d elle est négative, la présence d’un composant fractionnaire l’amène à être arrondie à l’entier plus petit. L’opération de cette méthode diffère de la méthode, qui prend en charge l’arrondi vers l’infini Ceiling positif.