C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Next: This example shows the Floor method being used on doubles that would be rounded down or rounded up with the Math.Round method.
DoubleInfo: In the example, the two numbers 123.456 and 123.987 are rounded down to the nearest integer.
And: This means that regardless of how close they are close to 124, they are rounded to 123.
Note: Floor can be useful when rounding numbers that are part of a larger representation of another number.
C# program that uses Math.Floor
using System;
class Program
{
static void Main()
{
//
// Two values.
//
double value1 = 123.456;
double value2 = 123.987;
//
// Take floors of these values.
//
double floor1 = Math.Floor(value1);
double floor2 = Math.Floor(value2);
//
// Write first value and floor.
//
Console.WriteLine(value1);
Console.WriteLine(floor1);
//
// Write second value and floor.
//
Console.WriteLine(value2);
Console.WriteLine(floor2);
}
}
Output
123.456
123 [floor]
123.987
123 [floor]
So: Using Math.Floor on a negative number will still decrease the total number. This means it will always become smaller.