Floating Point and Decimal Types in C Sharp

by Dinesh 2012-07-22 20:23:20

Floating Point and Decimal Types in C#

A C# floating point type is either a float or double. They are used any time you need to represent a real number, as defined by IEEE 754.
Decimal types should be used when representing financial or money values. table 2-2 shows the floating point and decimal types, their size, precision, and range.

The Floating Point and Decimal Types with Size, precision, and Range

Type Size (in bits) precision Range
float 32 7 digits 1.5 x 10-45 to 3.4 x 1038
double 64 15-16 digits 5.0 x 10-324 to 1.7 x 10308
decimal 128 28-29 decimal places 1.0 x 10-28 to 7.9 x 1028

Floating point types are used when you need to perform operations requiring fractional representations. However, for financial calculations, the decimal type is the best choice because you can avoid rounding errors.
940
like
0
dislike
0
mail
flag

You must LOGIN to add comments