Re: 1.0000023E+5 to 100000.23 as text?
Re: 1.0000023E+5 to 100000.23 as text?
- Subject: Re: 1.0000023E+5 to 100000.23 as text?
- From: "Mike Miller" <email@hidden>
- Date: Tue, 12 Dec 2000 14:21:57 -0600
Nigel Garvey <email@hidden> replied:
>
"Mike Miller" wrote on Mon, 11 Dec 2000 12:37:57 -0600:
>
>Jason Bourque <email@hidden> asked:
>
>>How would you go about converting scientific notation into text.
>
>
>
>Try the UnScientificNotate AppleScript snippet from the ESG Labs Snippets
>
>page(...)
>
>
This works very well, but still fails with the problem numbers I
>
mentioned earlier - such as 8439.39, which comes out as
>
"8439.389999999999".
I disagree that this is a failure. The script is successfully doing exactly what it says it will do and no more: you're passing in 8439.389999999999, and UnScientificNotate2() gives it right back to you as text. If you know how many decimal points you want, you should be using RoundToPrecision() or the new RoundToPrecision2() to get there.
Otherwise, you can complain to the designers of floating point representations, because this issue has been there forever. :)
>
I've now cured the bug in my previous effort and have rethought the logic
>
so that the relevant bits from the two handlers are combined into one.
>
Like UnScientificNotate, it produces results that look like integers or
>
reals, as appropriate, but it can't handle *quite* such large numbers! It
>
also produces a decimal point character to match the Numbers setting on
>
the host machine.
It looks good. I'm guessing numToStr() is faster than UnScientificNotate2(), while USN2 is slightly more complete (USN2 should handle any real you can throw at it, but I haven't spent a whole lot of time testing the two). In most uses, you'd probably pick numToStr().
However, I couldn't leave UnScientificNotate with the glaring decimal point/comma/whatever issue, so there's a new version of the UnScientificNotate snippet available which should fix that. It also adds RoundToPrecision2(), which fixes some issues with RoundToPrecision and gives you the option to keep trailing zeroes.
http://www.esglabs.com/snippets/
Hope this helps,
Mike Miller
ESG Labs
http://www.esglabs.com/