Passing a decimal number to 'display dialog'
Passing a decimal number to 'display dialog'
- Subject: Passing a decimal number to 'display dialog'
- From: Kai Edwards <email@hidden>
- Date: Mon, 16 Sep 2002 01:03:53 +0000
This may have cropped up before - but it's a new one on me.
While the 'display dialog' function would normally expect to be passed a
string, I recently used it to display the results of some calculations. For
the most part, the numbers were displayed as expected. However, in certain
conditions they were, well... not quite as expected.
For example:
---------------------------
display dialog 0.0 --> 0e+0
---------------------------
That aside, and with the exception of trailing zeros - which are truncated
(no biggie) - most numbers are displayed as entered/calculated, like this:
---------------------------
display dialog X.0 --> X
display dialog X.1 --> X.1
display dialog X.2 --> X.2
display dialog X.3 --> X.3
display dialog X.4 --> X.4
display dialog X.5 --> X.5
display dialog X.6 --> X.6
display dialog X.7 --> X.7
display dialog X.8 --> X.8
display dialog X.9 --> X.9
---------------------------
However, between 8.0 & 9.9, the numbers are displayed thus:
---------------------------
display dialog X.0 --> X
display dialog X.1 --> X.1
display dialog X.2 --> X.199999999999999
display dialog X.3 --> X.300000000000001
display dialog X.4 --> X.4
display dialog X.5 --> X.5
display dialog X.6 --> X.6
display dialog X.7 --> X.699999999999999
display dialog X.8 --> X.800000000000001
display dialog X.9 --> X.9
---------------------------
Between 10.0 & 63.9, the display of numbers reverts to the previous 'as
expected' pattern.
Then, between 64.0 & 99.9, the pattern changes to this:
---------------------------
display dialog XX.0 --> XX
display dialog XX.1 --> XX.09999999999999
display dialog XX.2 --> XX.2
display dialog XX.3 --> XX.3
display dialog XX.4 --> XX.40000000000001
display dialog XX.5 --> XX.5
display dialog XX.6 --> XX.59999999999999
display dialog XX.7 --> XX.7
display dialog XX.8 --> XX.8
display dialog XX.9 --> XX.90000000000001
---------------------------
Finally, from 100 upwards the 'normal' display appears to return. (Haven't
pursued things too far beyond this - there are a lot of numbers out there,
and I'm getting tired and hungry!) 8-O
This apparent quirk has been replicated on systems 8.x, 9.x and 10.x - so
it's pretty consistent. Since there's also a pattern here, I assume the
cause is to do with some internal algorithm.
The solution is, of course, to coerce the numbers to strings before passing
them to 'display dialog'. But I'm still somewhat curious about the reasons
for the behaviour.
Anyone?
Kai
--
email@hidden
email@hidden
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.