Search code examples
c#doublesuffix

What is the correct way of representing double in C#?


I am using the first way and my new company is using the second way.

double x = 1.99; 

double y = 9.02D; 

Which one is correct and why?

If both is correct, then how to use this is in different scenarios?


Solution

  • From msdn:

    By default, a real numeric literal on the right-hand side of the assignment operator is treated as double. However, if you want an integer number to be treated as double, use the suffix d or D, for example: Copy

    double x = 3D;

    So there is no difference between double x = 1.99; and double y = 9.02D;