Long Dual on iPhone

im working on an application that requires me to use a Long Double variable which in C / C ++ / ObjC must be accurate to 15 floats (1.123456789012345), the only problem is that on iphone i can only show up to 6 places ( 1.123456) using

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

      

I read that the iphone has bottlenecks in these values, but havent learned too much about it, who has any ideas how to get it to return 15 points as it should? thank!

+2


source to share


2 answers


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



See also this question .

+5


source


Long doubles are simply doubles on iPhone hardware. You are unfortunately not getting the extra precision you think you are. It worked a bit because the iPhone Simulator will handle long doublings correctly as it works on a Mac.



As Charles suggests, you need to use NSDecimal or NSDecimalNumber to get extra precision. In addition, the math involving these types will be free of the usual floating point problems that you see when handling decimal places.

+2


source







All Articles