Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Trying to go beyond roughly 16 digits of decimal precision with a <code>double</code> is generally <a href="http://en.wikipedia.org/wiki/Double_precision_floating-point_format" rel="nofollow noreferrer">not recommended</a>. Frankly, I'm surprised that you are able to represent this <code>double</code> (with 19 significant digits) in a way that maintains that precision when logging it out. You may even get different behavior on the iPhone itself, which maps a <code>long double</code> type to just plain <code>double</code> (your Mac may be handling this as a long double behind the scenes).</p> <p>The rounding you are seeing may be happening at the binary level (<a href="http://docs.sun.com/source/806-3568/ncg%5Fgoldberg.html" rel="nofollow noreferrer">see here for more on this</a>), so you won't be seeing the decimal rounding that you are expecting.</p> <p>It is for these reasons that you will want to work entirely with NSDecimalNumbers or NSDecimals from start to finish if you need this kind of high-precision math. To do this, do not convert to and from floating point types, but instead use NSStrings directly to populate and export the numbers (or store them as NSDecimalNumbers in Core Data).</p> <p>For example, you could work around the above problems with the following code:</p> <pre><code>id xxx = [NSDecimalNumber decimalNumberWithString:@"36.76662445068359375000"]; </code></pre> <p>NSDecimalNumbers (and their C struct equivalent NSDecimal) can handle up to 38 significant digits.</p>
 

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