## Objective-C Float, Double, Decimal

April 12, 2009 § 3 Comments

Float – 7 digits (32 bit)

Double-15-16 digits (64 bit)

Decimal -28-29 significant digits (128 bit)

Decimals have much higher precession and usually used within financial applications that require a high degree of accuracy. Decimals are much slower (up to 20X times in some tests) than a double\float.

Decimals and Floats/Doubles cannot be compared without a cast whereas Floats and Doubles can. Decimals also allow the encoding or trailing zeros.

Decimal doesn’t use IEEE floating point representation. It uses a decimal representation that is 100% accurate by doing decimal based math rather than base 2 based math. You can trust math to within the accuracy of decimal precision whereas you can’t fully trust floats or doubles unless you are very careful.

float is a single precision (32 bit) floating point data type as defined by IEEE 754 (it is used mostly in graphic libraries).

double is a double precision (64 bit) floating point data type as defined by IEEE 754 (probably the most normally used data type for real values).

decimal is a 128-bit floating point data type, it should be used where precision is of extreme importance (monetary calculations).

Yes, this explains to me about the difference between float, double and decimal.

Thanks for sharing.

Thank you!

Great summary! Thanks