Re: floats in (s)printf

new topic     » goto parent     » topic index » view thread      » older message » newer message

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 thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu