Decimal.Floor() Method in C#


The Decimal.Floor() method in C# rounds a specified Decimal number to the closest integer toward negative infinity.

Syntax

Following is the syntax −

public static decimal Floor (decimal val);

Above, Val is the value to round.

Example

Let us now see an example to implement the Decimal.Floor() method −

using System;
public class Demo {
   public static void Main(){
      Decimal val1 = 25.25m;
      Decimal val2 = 11.85m;
      Console.WriteLine("Decimal 1 = "+val1);
      Console.WriteLine("Decimal 2 = "+val2);
      Console.WriteLine("Floor (val1) = "+Decimal.Floor(val1));
      Console.WriteLine("Floor (val2) = "+Decimal.Floor(val2));
   }
}

Output

This will produce the following output −

Decimal 1 = 25.25
Decimal 2 = 11.85
Floor (val1) = 25
Floor (val2) = 11

Example

Let us now see another example to implement the Decimal.Floor() method −

using System;
public class Demo {
   public static void Main(){
      Decimal val1 = -25.25m;
      Decimal val2 = -11.85m;
      Console.WriteLine("Decimal 1 = "+val1);
      Console.WriteLine("Decimal 2 = "+val2);
      Console.WriteLine("Floor (val1) = "+Decimal.Floor(val1));
      Console.WriteLine("Floor (val2) = "+Decimal.Floor(val2));
   }
}

Output

This will produce the following output −

Decimal 1 = -25.25
Decimal 2 = -11.85
Floor (val1) = -26
Floor (val2) = -12

Updated on: 05-Nov-2019

476 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements