• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Coercing Numbers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Coercing Numbers


  • Subject: Re: Coercing Numbers
  • From: Luther Fuller <email@hidden>
  • Date: Fri, 26 Feb 2010 16:21:44 -0600

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.

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Coercing Numbers (From: Oakley Masten <email@hidden>)

  • Prev by Date: Re: Coercing Numbers
  • Next by Date: Re: Coercing Numbers
  • Previous by thread: Re: Coercing Numbers
  • Next by thread: file objects
  • Index(es):
    • Date
    • Thread