• 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: Simple multiplication going bizarre
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Simple multiplication going bizarre


  • Subject: Re: Simple multiplication going bizarre
  • From: "Stockly, Ed" <email@hidden>
  • Date: Thu, 29 Apr 2010 12:00:58 -0500
  • Acceptlanguage: en-US
  • Thread-topic: Simple multiplication going bizarre

Title: Re: Simple multiplication going bizarre
‘As number’ doesn’t do it. It’s the coercion to a text string that happens in Display Dialog that gives you the conversion.

set
myVal to 4999.0 * 12.5
display dialog myVal

Funny, though, as text still gives you an exponent


set myVal to 4999.0 * 12.5 as text
display dialog
myVal


‘As integer’ is no good, if you need fractional values (like when dealing with currency)

This is what I would use instead:

set
myVal to 4999.0 * 12.5
set
divVal to ((myVal div 1) as text)
set
modVal to (myVal mod 1) * 10 as integer
set myVal to divVal & "." & modVal
display dialog myVal

Same thing as a one-liner:
set
myVal to 4999.0 * 12.5
set
myVal to ((myVal div 1) as text) & "." & ((myVal mod 1) * 10 as integer)


All these solutions give you a text value. If you’re doing further calculations, I’d keep using the exponent version until you have to display the text value.

ES
 _______________________________________________
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: 
 >Re: Simple multiplication going bizarre (From: email@hidden)

  • Prev by Date: Re: Simple multiplication going bizarre
  • Next by Date: Simple multiplication going bizarre
  • Previous by thread: Re: Simple multiplication going bizarre
  • Next by thread: Simple multiplication going bizarre
  • Index(es):
    • Date
    • Thread