Tracks
/
C#
C#
/
Syllabus
/
Floating Point Numbers
Fl

Floating Point Numbers in C#

6 exercises

About Floating Point Numbers

There are three floating-point types in C#: double, float and decimal. The most commonly used type is double, whereas decimal is normally used when working with monetary data. A double is written as 2.45 or 2.45d, a float as 2.45f and a decimal as 2.45m.

Each floating-point type has its own precision, approximate range and size.

Some conversions between floating point types are automatic (implicit), but others are manual (explicit).

decimal account = 125m * (decimal)1.2f;

Always be careful when checking the values of floating-point types for equality, as values that can appear to represent the same value could actually be different. See this article for more information.

You can find a short introduction to floating-point numbers at 0.30000000000000004.com. The Float Toy page has a nice, graphical explanation how a floating-point numbers' bits are converted to an actual floating-point value.

Edit via GitHub The link opens in a new window or tab

Learn Floating Point Numbers

Practicing is locked

Unlock 5 more exercises to practice Floating Point Numbers