Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are asking for float, but in your code appears double.</p> <p>Anyway, neither float or double have always the same number of decimals. Float have assigned 32 bits (4 bytes) for a floating point representation according to IEEE 754.</p> <p>From <a href="http://en.wikipedia.org/wiki/Single_precision_floating-point_format" rel="nofollow noreferrer">Wikipedia</a>:</p> <blockquote> <p><img src="https://i.stack.imgur.com/eMPx0.png" alt="float representation"></p> <p>The IEEE 754 standard specifies a binary32 as having:</p> <ul> <li>Sign bit: 1 bit</li> <li>Exponent width: 8 bits</li> <li>Significand precision: 24 (23 explicitly stored)</li> </ul> <p>This gives from 6 to 9 significant decimal digits precision (if a decimal string with at most 6 significant decimal is converted to IEEE 754 single precision and then converted back to the same number of significant decimal, then the final string should match the original; and if an IEEE 754 single precision is converted to a decimal string with at least 9 significant decimal and then converted back to single, then the final number must match the original).</p> </blockquote> <p>In the case of double, from <a href="http://en.wikipedia.org/wiki/Double_precision_floating-point_format" rel="nofollow noreferrer">Wikipedia</a> again:</p> <blockquote> <p><img src="https://i.stack.imgur.com/HHbAB.png" alt="double representation"></p> <p>Double-precision binary floating-point is a commonly used format on PCs, due to its wider range over single-precision floating point, in spite of its performance and bandwidth cost. As with single-precision floating-point format, it lacks precision on integer numbers when compared with an integer format of the same size. It is commonly known simply as double. The IEEE 754 standard specifies a binary64 as having:</p> <ul> <li>Sign bit: 1 bit</li> <li>Exponent width: 11 bits</li> <li>Significand precision: 53 bits (52 explicitly stored)</li> </ul> <p>This gives from 15 - 17 significant decimal digits precision. If a decimal string with at most 15 significant decimal is converted to IEEE 754 double precision and then converted back to the same number of significant decimal, then the final string should match the original; and if an IEEE 754 double precision is converted to a decimal string with at least 17 significant decimal and then converted back to double, then the final number must match the original.</p> </blockquote> <p>On the other hand, you can't expect that if you have a float and print it out with more precision that the really stored, the rest of digits will fill with 0s. The compiler can't imagine the tricks you are trying to do.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload