float, double, and decimal

suggest change

float

float is an alias for the .NET type System.Single. It stores IEEE 754 single-precision floating-point numbers. These numeric types are part of the core libraries available to every C# project.

Approximate range: -3.4 × 10^38 to 3.4 × 10^38

Decimal precision: 6-9 significant digits

Notation:

float f = 0.1259f;
var f1 = 0.7895f; // f is the literal suffix for float values

It should be noted that the float type often results in significant rounding errors. In applications where precision is important, other data types should be considered.

double

double is an alias for the .NET type System.Double. It represents a double-precision 64-bit floating-point number. It is part of the core libraries available to every C# project.

Range: ±5.0 × 10^-324 to ±1.7 × 10^308

Decimal precision: 15-17 significant digits

Notation:

double distance = 200.34; // a double value
double salary = 245; // an int implicitly converted to double
var marks = 123.764D; // D is the literal suffix for double values

decimal

decimal is an alias for the .NET type System.Decimal, a 128-bit decimal floating-point type. Compared with binary floating-point types, decimal has more precision and a smaller range, which makes it appropriate for financial and monetary calculations. It is part of the core libraries available to every C# project.

Range: ±7.9 × 10^28

Decimal precision: 28-29 significant digits

Notation:

decimal payable = 152.25m; // a decimal value
var marks = 754.24m; // m is the literal suffix for decimal values

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents