Re: sprintf() precision arbitrarily at six decimal places?

new topic     » goto parent     » topic index » view thread      » older message » newer message
petelomax said...
euphoric said...

I have an atom of value with 8 decimal places. When I want to use it in an API call, I have to make it text; I generally use sprintf("%f",{v}) because I cannot have exponential notation. However, I just recently discovered that sprintf() and sprint() do not return my complete number! I was shocked to discover this.

You really should hold the precise number it needs and specify that as eg %.8f - I remember having much trouble trying to figure out how many dp each of the various API args needed, especially when the requirements for the same field often changed from one call to the next.

Be warned: some of those API calls kicked me for passing too many trailing zeroes.

Yes, and that's why I can't use a one-size-fits-all "%.8f" string. So, I'm just going out to 15 dp and lopping off the extra zeroes, then truncating to the dp that is actually required.

petelomax said...

Independently of that, using the max 16dp can trigger the odd 0.1234000000000001 whereas using say 12 dp would round that glitch away.

I'll keep an eye out for that. grin

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

Search



Quick Links

User menu

Not signed in.

Misc Menu