UInt64 sum = 16494631536958187520UL;
double doubleSum = sum;
NSString *strSum = [ NSNumberFormatter localizedStringFromNumber:
@(doubleSum)
numberStyle: NSNumberFormatterDecimalStyle
];
NSLog(@"%s DecimalStyle (of double): %@; UInt64: %llu, double:
%.22g",__FUNCTION__, strSum, sum, doubleSum );
This prints:
DecimalStyle (of double): 16,494,631,536,958,200,000; UInt64:
16494631536958187520, double: 16494631536958187520
Note: converting to double does NOT loose any digits. But NSNumberFormatter
does. Why?
I also tried:
NSNumberFormatter *nf = [ [ NSNumberFormatter alloc ] init ];
[ nf setNumberStyle: NSNumberFormatterDecimalStyle ];
[ nf setUsesSignificantDigits: YES ];
[ nf setMaximumSignificantDigits: 22 ];
NSString *str2Sum = [ nf stringFromNumber: @(doubleSum) ];
But the result is the same.
Gerriet.
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]