1. floats in (s)printf

i just noticed that printf and sprintf by default display like 6
digits after the decimal place or something like that with %e, %f and %g...
i was wondering it were possible (practical) to have some way of
displaying just enough digits that would still give all the accuracy of the
number...  i.e.  if i were to do a printf(1,"%f",5.5) it would print out
"5.5", but if i were to do a printf(1,"%f",5.55555555555555555) it would
print out that number to 15 decimal places or whatever it is...  you know
what i'm saying??  okay

new topic     » topic index » view message » categorize

2. Re: floats in (s)printf

Mike Burrell <mikpos at USA.NET> wrote:
>i just noticed that printf and sprintf by default display like 6
>digits after the decimal place or something like that with %e, %f and >%g... i
was wondering it were possible (practical) to have some way >of displaying just
enough digits that would still give all the >accuracy of the number...  i.e.
if i were to do a printf(1,"%f",5.5) >it would print out "5.5", but if i were
to do a >printf(1,"%f",5.55555555555555555) it would print out that number to
>15 decimal places or whatever it is...  you know what i'm saying?? >okay

What if you were to store 5.5555 or whatever as a sequence (  {5}, {5}, {5}
etc.--every element after the first being right of the decimal)?  Then you
could build a  structure that would print it with only the number of decimals
needed.  My attempt is below.  There's probably a beter way of doing what
you're talking about (This way is not very convenient and probably not very
efficient smile  And of course the sequence is not the actual number, and there
are a million other problems.  But it was a thought.  Good luck

Joshua Milligan

Here's my attempt:
--------------------------------start of code
sequence fives
fives = {{5}, {5}, {5}, {5}, {5}, {5}, {5}}

printf (1, "%g.", fives[1])

for i = 2 to length(fives) by 1 do
printf (1, "%g", fives[i])
end for
---------------------------------end code

---------------------------------------------------------
Get Your *Web-Based* Free Email at http://www.hotmail.com
---------------------------------------------------------

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

3. Re: floats in (s)printf

> i just noticed that printf and sprintf by default display like 6
> digits after the decimal place or something like that with %e, %f and
%g...
> i was wondering it were possible (practical) to have some way of
> displaying just enough digits that would still give all the accuracy of
the
> number...  i.e.  if i were to do a printf(1,"%f",5.5) it would print out
> "5.5", but if i were to do a printf(1,"%f",5.55555555555555555) it would
> print out that number to 15 decimal places or whatever it is...  you know
> what i'm saying??  okay

Well, Euphoria does allow specification of field width and decimal
precision for displaying numbers. For example, %6.3f means a field width of
6 positions with a precision of 3 decimal points. I don't know if it goes
to 15 decimal points however...never tried.

Hope this helps

David Gay
http://www.interlog.com/~moggie/Euphoria
"A Beginner's Guide To Euphoria"

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

Search



Quick Links

User menu

Not signed in.

Misc Menu