What is the difference between a float, double and a decimal in C#?

CsharpProgrammingServer Side Programming

Float , double and a decimal are all Value Types in C#.

Value type variables can be assigned a value directly. They are derived from the class System.ValueType. The value types directly contain data.

Float Value Type

Float is a 32-bit single-precision floating point type with range 3.4 x 1038 to + 3.4 x 1038

Memory Size is 4 bytes.

float a = 3.5f;

Double Value Type

Double is a 64-bit double-precision floating point type with range (+/-)5.0 x 10-324 to (+/-)1.7 x 10308

Memory Size is 8 bytes.

double d = 5.78788

Decimal Value Type

Decimal is a 128-bit precise decimal values with 28-29 significant digits with range (-7.9 x 1028 to 7.9 x 1028) / 100 to 28

Memory Size is 16 bytes.

decimal d = 1.0M;
Published on 08-Aug-2018 10:45:51