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

Re: Currency Numbers


  • Subject: Re: Currency Numbers
  • From: "Nigel Garvey" <email@hidden>
  • Date: Thu, 29 Jun 2006 04:08:52 +0100

nino wrote on Wed, 28 Jun 2006 19:51:02 +0200:

>Hi,
>> on currency_format for v
>> tell (v mod 1 as text) * 100 to (v div 1 as text) & (0.0 as text)'s
>> character 2 & ((it * it) ^ 0.5 + 0.5) div 1
>> end currency_format
>the full tread it's very interesting and I've learned a lot ... but
>
> currency_format for -123.995 => "-123,100" on an Italian system.
>
>Since all that was aimed at roundig currency format it shuld be "124.00".
>
>so here is my suggestion
>
>on currency_format for v
>    ((round v * 100) div 100 as text) & text 2 thru 4 of (((abs (round (v
>mod 1 * 100)) / 100) as string) & "0")
>end currency_format

Well spotted, nino! We completely forgot about possible carries.

Here's a vanilla version that incorporates everyone's ideas.  :-)

  on currency_format for v
    tell ((((v mod 1 as text) * 100) ^ 2) ^ 0.5 + 0.5) div 1 to return
((v div 1 + it div 100 * (1 - 2 * ((v < 0) as integer))) as text) & text
2 thru 4 of ((it / 100 + 1.001) as string)
  end currency_format

  currency_format for -123.995 --> "-124.00" or "-124,00"

  currency_format for -321.255 --> "-321.26" or "-321,26"

Surprisingly, this works in Jaguar too. I didn't think boolean to integer
coercions were around then.

NG

 _______________________________________________
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: "Nigel Garvey" <email@hidden>
  • Prev by Date: Re: Add/Remove from Dock?
  • Next by Date: AppleEvent for fast user switching?
  • Previous by thread: Re: Currency Numbers
  • Next by thread: Re: Currency Numbers
  • Index(es):
    • Date
    • Thread