johnezang/JSONKit — Issue #63: Integral double values are encoded as integers
Author: arschles
Created: 2011-11-22 01:25:58+00:00
State: open

if I run this code:

```objectivec
static NSString * key = @"doubleKey";
NSNumber * doubleNumber = [NSNumber numberWithDouble:22];
NSMutableDictionary * dict = [NSMutableDictionary dictionary];
[dict setObject:doubleNumber forKey:key];
NSLog("%@", [dict JSONString]);
```

I get this json:

```json
{"doubleKey":22}
```

I'm not intimately familiar with the JSON spec, but this encoding was causing me some problems where I expected a double to come back on decode, but an int came back.

I implemented a possible fix locally, but I'd like to hear feedback before I fork and submit a pull request. The fix is to change the format string at https://github.com/johnezang/JSONKit/blob/master/JSONKit.m#L2755, which is currently ```"%.17g"``` to ```"%#.17g"``` in order to force trailing zeroes for double values that are also whole numbers.