There are several ways to indicate real number (floating point) literals in C#. Real literals are assumed to be of typedouble, but may also be of type float or decimal, depending on the suffix included with the literal.
Suffix / type:
- f – float
- d – double
- m – decimal
Here are some examples:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| // Suffixesdouble d1 = 1.0; // okobject o1 = 1.0; // Also doublefloat f1 = 3f; // floatfloat f2 = 1.0f; // Must have 'f' suffix for floatdouble d2 = 1.0d; // Optional 'd' suffixdecimal d3 = 1.0m;// Exponentsdouble d4 = 1.2E3; // 1200double d5 = 1.2E+3; // 1200double d6 = 1.2E-3; // 0.0012double d7 = 2E3; // 2000double d8 = 2E-3; // 0.002float f3 = 2E-3f;decimal d9 = 2E-3m; |

