Answers for "C# if there is a decimal portion"

C#
0

C# if there is a decimal portion

For floating point numbers, n % 1 == 0 is typically the way to check if there is anything past the decimal point.

public static void Main (string[] args)
{
    decimal d = 3.1M;
    Console.WriteLine((d % 1) == 0);
    d = 3.0M;
    Console.WriteLine((d % 1) == 0);
}

//Output:
False
True
Posted by: Guest on April-06-2021

Code answers related to "C# if there is a decimal portion"

C# Answers by Framework

Browse Popular Code Answers by Language