On Feb 26, 2010, at 2:01 PM, Oakley Masten wrote:
I can't find the answer to this and don't know where else to look.
set x to 24.95 * 100
--> x = 2495.0
set x to 124.95 * 100
--> x = 1.2495E+4
if I set XasText to (x as text)
I still get 1.2495E+4
How do I get this to show up as 12495 ?
I have two solutions. First, the long one ...
tell application "Finder"
set x to (capacity of startup disk) -- for example
end tell
display dialog my nonExp(x)
on nonExp(x)
class of x
if (the result is not real) and (the result is not integer) then error "Input to nonExp is not a number."
set AppleScript's text item delimiters to {"E"}
try
set exponent to (text item 2 of (x as text)) as integer
on error
return x -- there is no "E" in x
end try
set x to (x / (10 ^ exponent)) as text
set AppleScript's text item delimiters to {"."}
repeat (exponent - (length of text item 2 of x)) times
set x to (x & "0")
end repeat
set x to (text items of x)
set AppleScript's text item delimiters to {""}
set x to (x as text)
return x
end nonExp -----------------------------------------
-- this only works if "E" is followed by "+".
-- A little homework might add a few lines of code to fix that.
And now the short solution.
tell application "Finder"
set x to (capacity of startup disk) -- for example
set selfRef to (path to me)
set comment of selfRef to x
get comment of selfRef
display dialog the result
end tell
It seems that the Finder removes the exponential notation when it writes a number.