How to convert JSON Data (Dictionary) to JSON String without changing number of decimal points in Objective C?

120 views Asked by At

When I convert JSON data which contains double value like 4999.99 to JSON String it outputs with different value with multiple decimal points like 4999.9899999999998

I used the following code for JSON NSJSONSerialization and encoding.

jsonData = [NSJSONSerialization dataWithJSONObject:dataDic options:1 error:&error];

jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; 

In dataDic there has key/value pairs like @amount: (double)4999.99

but in jsonString contains "amount" : 4999.9899999999998, instead of 4999.99

Please help me to get jsonstring to as dataDic values correctly.

0

There are 0 answers