-2

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
Iharob Al Asimi
  • 52,653
  • 6
  • 59
  • 97
Peter
  • 1,053
  • 13
  • 29

1 Answers1

1

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.

Starlord
  • 313
  • 1
  • 9