Double printing same as float

63 Views Asked by At

Why is my double variable storing and printing as a float. Using Xcode.

 #import <limits.h>
 #import <Foundation/Foundation.h>

 long double doubleTest = .123456789101112;
 float floatTest = .123456789101112;

 NSLog(@"Float %f vs Double %Lf", floatTest, doubleTest);

// Output - Float 0.123457 vs Double 0.123457
1

There are 1 best solutions below

0
Starlord On BEST ANSWER

Try this

long double doubleTest = .123456789101112;
float floatTest = .123456789101112;

NSLog(@"Float %.nf vs Double %.nLf", floatTest, doubleTest);

replace "n" in the above line with however many number's you'd like to print after decimal point, for instance if you use 6 it will print 6 digits after decimal.

Hope this helps.