force non-scientific notation of numbers
I have a number like -4.43e-05 in Perl.
I want to produce JSON like "longitude" : -0.0000443, (decimal notation)
but if I do encode_json [-4.43e-05] I get -4.43e-05 (scientific notation).
If I first format my number with something like sprintf('%.7f',$num) to take it out of scientific notation, the result is a string, not a number, and I then get JSON like "longitude" : "-0.0000443",.
I can't seem to find a way to force numbers in the JSON output (as opposed to strings) to be represented in decimal notation. Am I overlooking something?
Thanks for your help.
I'm afraid, but you cannot do that. JSON::XS will aways return the result of the internal number conversion Gconvert (or quadmath_snprintf), which usually is %g, definable in config.h.
Only inf/nan are exceptions.
You might try to persuade upstream JSON to add such a feature.
thanks for the fast answer, even if it's not what i was hoping to hear
I leave it open, as it really is an upstream decision to add a custom number formatter hook. If JSON decides to add such an option, Cpanel::JSON::XS will happily follow. Please add a link to this ticket here, if you open a ticket there. (url is enough)