• 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
Currency Numbers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Currency Numbers


  • Subject: Currency Numbers
  • From: Yvan KOENIG <email@hidden>
  • Date: Mon, 26 Jun 2006 18:14:40 +0200

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Currency Numbers
      • From: kai <email@hidden>
  • Prev by Date: Re: Dabbling with EXIF
  • Next by Date: Re: Currency Numbers
  • Previous by thread: Re: Currency Numbers
  • Next by thread: Re: Currency Numbers
  • Index(es):
    • Date
    • Thread