Ariel Zehao Zhang
Ariel Zehao Zhang

Reputation: 564

About NSNumber numberWithDouble

double test1 = 5.58f;

NSString *test2 = @"5.58";

NSLog(@"%@", [NSNumber numberWithDouble:test1]);

NSLog(@"%@", [NSNumber numberWithDouble:[test2 doubleValue]]);

Output:

5.579999923706055

5.58

Why the convert is difference?

Upvotes: 1

Views: 2333

Answers (1)

borrrden
borrrden

Reputation: 33421

Probably due to the fact that 5.58f is a float, not a double.

Upvotes: 3

Related Questions