Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Currency Numbers



Le 26 juin 2006, à 12:34, David Bradley a écrit :

Cheers kai,

Your code below worked a treat. I did treat other suggestion but they only gave me one decimal place.

However, I have had to put it as straight code rather than as a handler due to the fact that I get the error: Can't continue currency_format.

I had written the call to the handler as follows:

set strCatBSP to strCatBSP)


Hello

-- 1 -- as the handler uses the syntax :
on currency_format for v,
the calling instruction seems to be required to use the same one:
set strCatBSP to currency_format for strCatBSP


-- 2 -- Even with this syntax something bothers me.
The passed strCatBSP is assumed to be a number
but the returned one is a string.

-- 3 -- Used in french config, the script returns a foolish result

History:
tell current application
round -40.000000000001
-40
offset of "." in "-0,4"
0
end tell

Result:

"-123.-0"

because the french decimal separator is not a period as was explained several times in this thread.

To get a correct behaviour worldwide, the handler need some changes like this version:

on currency_format for v
set d to (round (v mod 1 * 100)) / 100 as string
set decimalSep to character 2 of (0.0 as string)
(v div 1 as text) & "." & text 1 thru 2 of (d's text ((offset of decimalSep in d) + 1) thru -1 & "00")
end currency_format

History:
tell current application
round -40.000000000001
-40
offset of "," in "-0,4"
3
end tell

Result:
"-123.40"

In fact this version (which I sent by mistake to David Bradley) is not really correct because the returned string doesn't match the format used in France for numerical strings.
The correct one would be:

on currency_format for v
set d to (round (v mod 1 * 100)) / 100 as string
set decimalSep to character 2 of (0.0 as string)
(v div 1 as text) & decimalSep & text 1 thru 2 of (d's text ((offset of decimalSep in d) + 1) thru -1 & "00")
end currency_format

Result:
"-123,40"

Yvan KOENIG (from FRANCE)
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-users/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.