Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Represent double value as NSString

What is the correct way of represent double value as NSString ? In my code, it is calculating or rather doing some kind of rounding..I am not sure. Below is my code;

X = [NSString stringWithFormat:@"%d", [abc doubleValue] - [xyz doubleValue]];

I am getting abc is 69206000000, xyz is 31687000000, X is 58720256

Please help me.

like image 882
copenndthagen Avatar asked Feb 10 '11 18:02

copenndthagen


2 Answers

Use the %f format modifier to display a double value - the %d in your code refers to an integer value. (See String Format Specifiers for more info.)

like image 76
Tim Avatar answered Oct 18 '22 07:10

Tim


Use %lf for double value

X = [NSString stringWithFormat:@"%lf", [abc doubleValue] - [xyz doubleValue]];

Hope this will help you.

like image 35
sinh99 Avatar answered Oct 18 '22 09:10

sinh99