Mailing Lists: Apple Mailing Lists

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

Re: Currency Numbers



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:
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.