number formatting, dollars and sense

Newbie here. Forgive me if this has already been discussed. I searched the BBS and the Scripting Additions section but couldn’t find what I’m looking for.

I have written several scripts that parse selected (clipboard) financial information and accumulate subtotals and grand totals. I wrote a subroutine to format passed results as dollars and cents using string operations. No problem, worked pretty well until I got to numbers greater than 10,000 plus change. As far as I can tell, AppleScript uses scientific notation when such real numbers are coerced into strings. I figured a way to decompose the parts of a real number using Div and Mod operators. Then I wondered if there wasn’t a Scripting Addition or hidden AS command to format numbers like HyperCard’s “number format” command. Is there such a beast?

AppleScript coerces numbers to string according with your preferences in the International Panel. In my system:

5555.55 as string
--> "55555,55"

Satimage has a command called “format”, which may help you:
http://www.satimage.fr/software/en/softx.html#osax

However, you must also consider the International preferences. For instance, the sample for this command fails for me:

format pi into "##.##" --> "3"

Since my decimal separator is “,” (comma).
A quick “universal” workaround to guess user’s decimal separator is the following:

set userDecimalSeparator to item 2 of (1.1 as string) --> here ","

format pi into "##" & userDecimalSeparator & "##" --> "3,14"

jj is right, the Satimage OSAX (freeware) works well. For standard US monetary notation, try:

Jon


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

Thanks jj and jonn8. I will give satimage a try.

Worked like a charm once I removed the code from a Finder tell statement, a mistake I frequently make. I also changed the format string to fill with trailng zeroes (“###,###.00”).