We have three sizes to choose from, depending on if we want to store numbers using more or less significant digits. For numbers with few significant figures (up to 7, which is known as a "single-precision real data") we can use "float" data type, and if we need more accurate numbers (about 15 digits, "double precision") we have "double" data type. In C# we have a third type of real numbers, even more accurately, called "decimal":
| float | double | decimal |
Size (bits) | 32 | 64 | 128 |
Biggest value | -1,5·10-45 | 5,0·10-324 | 1,0·10-28 |
Smallest value | 3,4·1038 | 1,7·10308 | 7,9·1028 |
Significant figures | 7 | 15-16 | 28-29 |
To define them, we do as we did for integers:
float x;
And we can assign a starting value at the time of defining them (remembering that the decimal places we should not use a comma, but a point):
float x = 12.56;
No comments:
Post a Comment