Re: Simple calculation
Re: Simple calculation
- Subject: Re: Simple calculation
- From: Mark Butcher <email@hidden>
- Date: Fri, 25 Jan 2002 14:21:50 -0800
Rob wrote:
...I get the result 1.63875E+4 which is all well and good but the script
forwards the figure to our accountant who is foxed by figures that
aren't in
the format #16387.50
Here's something that solves your particular problem:
set theCost to 327.75 * 50
--check number is greater than 1
if theCost b % 1 then
--keep the number as a string
set theCost to theCost as string
--check if number is represented with an exponent
try
offset of "E" in theCost
--Get rid of the decimal point
set AppleScript's text item delimiters to "."
set theCost to text items of theCost
set AppleScript's text item delimiters to ""
set theCost to theCost as string
--seperate the number from the exponent
set AppleScript's text item delimiters to "E"
set theNumber to text item 1 of theCost
set theExponent to text item 2 of theCost as number
--put the decimal point in the right place in the number
set AppleScript's text item delimiters to ""
set theCost to (characters 1 thru (theExponent + 1) of
theNumber) & "." & (characters (theExponent + 2) thru (count of
characters of theNumber) of theNumber) as string
end try
end if
set theCost to "#" & theCost
Watch the line wrap on the long line before the 'end try', Also the
script assumes the decimal point is represented by a period, whereas a
lot of countries (and the ISO standard) use a comma. I've got a nasty
feeling that there must be a more elegant way of doing this.
Hope this helps
MarkB