views:

175

answers:

2

hi, im working on an application that requires me to use a Long Double variable, which, in C/C++/ObjC, should be precise up to 15 floating values (1.123456789012345), the only issue is that on the iphone, i can only seem to display up to 6 places (1.123456) using

NSString *display = [NSString stringWithFormat:@"%Lf",value];

I was reading that the iphone bottlenecks these values but havent found out too much on it, anyone have any ideas how to get it to return 15 points like it should? thanks!

+1  A: 

NSDecimalNumber will give you up to 38 digits of precision. NSDecimalNumbers are not native long doubles, but some type conversions are supported.

See also This question.

Charles
A: 

Long double simply maps to double on the iPhone hardware. You unfortunately don't get the extra precision that you'd think you would. This tripped me up early on, because the iPhone Simulator will handle long doubles correctly, as it is running on a Mac.

As Charles suggests, you'll need to use NSDecimal or NSDecimalNumber to get that extra precision. Additionally, math involving those types will be free of the normal floating point issues you see when handling decimals.

Brad Larson