Decimal.Floor() Method in C#
Last Updated :
29 Jan, 2019
This method is used to round the decimal to the closest integer toward negative infinity.
Syntax: public static decimal Floor (decimal d);
Parameter:
d: This parameter specifies the decimal which will be rounded off.
Return Value: If d has a fractional part, the next whole Decimal number toward negative infinity that is less than d or d doesn’t have a fractional part, d is returned unchanged. Note that the method returns an integral value of type Decimal.
Below programs illustrate the use of Decimal.Floor(Decimal) Method:
Example 1:
using System;
using System.Globalization;
class GFG {
public static void Main()
{
Decimal a = 4.01m;
Decimal value = Decimal.Floor(a);
Console.WriteLine( "Floor Value is : {0}" ,
value);
}
}
|
Output:
Floor Value is : 4
Example 2:
using System;
using System.Globalization;
class GFG {
public static void Main()
{
Decimal a = -5.03m;
Decimal value = Decimal.Floor(a);
Console.WriteLine( "Floor Value is : {0}" ,
value);
}
}
|
Output:
Floor Value is : -6
Example 3:
using System;
using System.Globalization;
class GFG {
public static void Main()
{
Decimal a = 2.00m;
Decimal value = Decimal.Floor(a);
Console.WriteLine( "Floor Value is : {0}" ,
value);
}
}
|
Output:
Floor Value is : 2
Share your thoughts in the comments
Please Login to comment...