1. %g format again

Rob:
Due to a problem with my ISP, I lost a bunch of messages from Euphoria, so I
don't know if you answered my last e-mail on the subject.
The question is:
Why the last item in the following line is printed with only 5 decimals?

printf(1, "%g %g %g %g %g\n", {5, 5.00, 5.100000, 5.1200000, 5.12345678})

5 5 5.1 5.12 5.12346

I think the main utility of the %g format is to show the minimum exact
representation of numbers, so you are not concerned to whether they are
integers or fractional, or how many digits comprise the fraction part.

Because of this problem, PRINT.E by Gabriel Boehme does not give the same
results as standard print().

new topic     » topic index » view message » categorize

2. Re: %g format again

rforno writes:
> Why the last item in the following line is printed with only 5 decimals?
>
> printf(1, "%g %g %g %g %g\n", {5, 5.00, 5.100000, 5.1200000, 5.12345678})
> 
> 5 5 5.1 5.12 5.12346

I'm using C's %g to implement Euphoria's %g.
I guess 5 is the default chosen by the C implementers.
If you want more digits you can specify a field width and a precision.
Try some experiments.

Regards,
   Rob Craig
   Rapid Deployment Software
   http://www.RapidEuphoria.com

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu