Bill Allombert on Thu, 18 Jan 2024 23:42:32 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: print() does output numbers in scientific notation violating JSON number spec


On Thu, Jan 18, 2024 at 11:09:49PM +0100, hermann@stamm-wilbrandt.de wrote:
> From latest JSON rfc:
> 
> ? version
> %2 = [2, 15, 4]
> ? print(0.00001)
> 1.0000000000000000000000000000000000000 E-5
> ?
> 
> I use PARI/GP to write a JSON file, that is read by JavaScript/nodejs.
> And that errors out on reading above number.
> If I manually remove the space, "1.0000000000000000000000000000000000000E-5"
> can be processed easily.

You can do 
default(output,0)
(\o0)

? \o0
? print(0.00001)
1.0000000000000000000000000000000000000E-5

> Is there an option to make PARI/GP produce "0.00001" as output instead of
> scientific representation?

? printf("%f",0.000000000000000000001)
0.0000000000000000000010000000000000000000000000000000000000
or even
? default(format,"f.38")
? print(0.00001)
0.000010000000000000000000000000000000000000

Cheers,
Bill