Eric Lemoine wrote:
> I just meant that {"pi": "3.14"} is different than {"pi": 3.14}.

go it.

> It's simplejson's job. And here's what simplejson does (current trunk):
> 
> # Assume this produces an infinity on all machines (probably not guaranteed)
> INFINITY = float('1e66666')
> FLOAT_REPR = repr
> 
> def floatstr(o, allow_nan=True):
>     # Check for specials.  Note that this type of test is processor- and/or
>     # platform-specific, so do tests which don't depend on the internals.
> 
>     if o != o:
>         text = 'NaN'
>     elif o == INFINITY:
>         text = 'Infinity'
>     elif o == -INFINITY:
>         text = '-Infinity'
>     else:
>         return FLOAT_REPR(o)
> 
>     if not allow_nan:
>         raise ValueError("Out of range float values are not JSON compliant: 
> %r"
>             % (o,))

All the real work is done in FLOAT_REPR -- so what is that? I'd expect 
it to be something like:

def FLOAT_REPR(f, Precision=8):
     format_str = "%%.%ig"%Precision
     return format_str%f


If that's the case, then it would work with Decimals too, though the 
specials check would probably need some adjustment.

-Chris


-- 
Christopher Barker, Ph.D.
Oceanographer

NOAA/OR&R/HAZMAT         (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception
_______________________________________________
Community mailing list
[email protected]
http://lists.gispython.org/mailman/listinfo/community

Reply via email to