stig/json-framework — Issue #113: Converting NSNumber to JSON representation
Author: felipebvalio
Created: 2011-12-01 15:34:14+00:00
State: open

I am using the framework version 3.1, and found an issue about converting a NSNumber with float/double to JSON representation. Some dirty decimal cases are added at rightmost digits, like 4.4 being converted to 4.4000000953674316

In SBJsonStreamWriter class, the NSNumber is being forced to be represented with 17 decimal cases with the code:

snprintf(num, sizeof num, "%.17g", [number doubleValue]);

As far as I know, double has 14 cases and float, 7. Moreover, is being used ever double, even when passing a float NSNumber.
Replacing the "%.17g" by "%g" resolved my problems.