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



On 2006/06/29, at 8:07, Nigel Garvey wrote:

I wrote on Thu, 29 Jun 2006 04:08:52 +0100:

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

OK. We could lose a couple of multiplications from that:

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


  currency_format for -123.995 --> "-124.00" or "-124,00"
  currency_format for -321.255 --> "-321.26" or "-321,26"

This seems to be the fastest so far, thanks to nino's idea of getting the
decimal "point" character with the 'mod 1' string coercion.

Someone may have pointed this out already -- I haven't been paying close attention to this thread -- but this is all somewhat pointless if what you want is what the message title says, namely the number formatted as currency, because not all countries use two decimal places for their currency, not to mention the fact that you haven't got the currency symbol. I'd add some decent numeric formatting features to AppleScript, but then what would all of you do for entertainment?



--Chris Nebel AppleScript Engineering

_______________________________________________
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
References: 
 >Re: Currency Numbers (From: "Nigel Garvey" <email@hidden>)
 >Re: Currency Numbers (From: "Nigel Garvey" <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.