using Math.Floor

838 views Asked by At

I am trying to use the Math.Floor method on 2 user-input numbers but whenever I try to use the Math.Floor with my input3 and input3a it just doesn't work. I've seen examples for already set numbers such as in an array but not of numbers that the user inputs. Any help/clarification would be awesome.

static void Minimum()
    {
        Console.WriteLine("\n Enter two numbers and I shall determine the Minimum:\n");
        Console.Write("> ");
        Console.Write("\n> ");
        // Read and parse input
        string input3 = Console.ReadLine();
        double d_input3 = Double.Parse(input3.Trim());
        string input3a = Console.ReadLine();
        double d_input3a = Double.Parse(input3a.Trim());

        // Determine minimum of numbers

            Console.WriteLine("\nThe Number {0} and {1}.\n", d_input3, d_input3a);
    }
2

There are 2 answers

1
AlexH On BEST ANSWER

If think you don't need Math.Floor to determine a minimum :

Returns the largest integer less than or equal to the specified double-precision floating-point number.

If you need to determine the minimum of both numbers, use Math.Min instead

Console.WriteLine("\nThe minimum number between {0} and {1} is {2}.\n", d_input3, d_input3a, Math.Min(d_input3, d_input3a));
2
Guffa On

The Math.Floor function takes one parameter and returns the value rounded down:

d_input3 = Math.Floor(d_input3);
d_input3a = Math.Floor(d_input3a);

The Math.Floor method is however not used to determine the lower value of two values. For that you would use the Math.Min function instead:

double lowest = Math.Min(d_input3, d_input3a);