The most common floating-point format, IEEE 754, includes a basic 32-bit format and a basic 64-bit format, and these are commonly used for the float
and double
types in C. For brevity, I will call them float
and double
in this answer.
Neither of these types can exactly represent non-integer numbers other than those that are multiples of a power of two (such as ¼, ¾, 1/1024, 73/1048576). Every other number will be changed slightly when it is converted from decimal to float
or double
.
However, the float
has the property that rounding any decimal numeral with six significant digits (such as 1.2345 or 9.87654e23) to float
and back to six significant decimal digits returns the original number (provided the number is within normal bounds of the format). In C, this number of digits is reported by the value FLT_DIG
, which is defined by float.h
. Since your number 78.352361 has eight significant digits, it is not guaranteed to survive a conversion to float
and back.
For double
, at least 15 digits will survive a round trip, reported by DBL_DIG
.
Note that this is the number of decimal digits guaranteed to survive the rounding caused by one conversion to binary floating-point and back to the original number of decimal digits. If additional arithmetic is performed in floating-point, additional roundings occur, which may accumulate more error. And, if a value is formatted with more decimal digits than the original, then the result may differ from the original number. (For example, .9f
produces “.9” when converted back to one decimal digit but “0.899999976” when converted to nine decimal digits.)
Since double
guarantees that 15 digits survive a round trip, your number 78.352361 would survive a conversion to double
and back to eight significant digits unchanged. Additionally, there is enough precision to perform some arithmetic without accumulating so much error that it is visible in eight significant decimal digits. However, floating-point arithmetic can be tricky, and a complete error analysis depends on the operations you perform.