• 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: Christopher Nebel <email@hidden>
  • Date: Thu, 29 Jun 2006 11:08:12 -0700

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Currency Numbers
      • From: Shane Stanley <email@hidden>
    • Re: Currency Numbers
      • From: "J. Stewart" <email@hidden>
References: 
 >Re: Currency Numbers (From: "Nigel Garvey" <email@hidden>)
 >Re: Currency Numbers (From: "Nigel Garvey" <email@hidden>)

  • Prev by Date: Re: What's going on here?
  • Next by Date: Re: What's going on here?
  • Previous by thread: Re: Currency Numbers
  • Next by thread: Re: Currency Numbers
  • Index(es):
    • Date
    • Thread