Re: Currency Numbers
Re: Currency Numbers
- Subject: Re: Currency Numbers
- From: "Nigel Garvey" <email@hidden>
- Date: Wed, 21 Jun 2006 21:01:13 +0100
Yvan KOENIG wrote on Tue, 20 Jun 2006 09:38:08 +0200:
>Le 20 juin 2006, à 04:35, Nigel Garvey a écrit :
>>
>>
>> If I switch my machine over to French and French numbers, it's only in
>> strings that the decimal point is a comma. It still appears as a dot in
>> reals in Script Editor. Is that true for French users or have I missed
>> something?
>>
>> NG
>
>
>Hello
>
>You are perfectly right Nigel.
Thanks for the information, Ivan. It's good to know that '0.0 as string'
is fully portable and that further circumlocutions like '1 / 2 as string'
or '0 as real as string' aren't necessary.
kai wrote on Tue, 20 Jun 2006 21:23:41 +0100:
>Very nicely optimised for performance, too - although, on my machine,
>this seems to *just* have the edge (by a mere squeak):
I guessed you'd be having a go at improving it. :-)
From your later, corrected post:
>on currency_format for v
> tell (((v mod 1 as text) * 100) ^ 2) ^ 0.5 + 0.5 to (v div 1 as
>text) & (0.0 as text)'s character 2 & it div 1
>end currency_format
>
>currency_format for -123.4
Nice one. :-) Since the figure to be rounded is rendered positive
anyway, the "add 0.5 and div by 1" method can be used, which is one less
step than 'it div 0.5 - it div 1'. Also 'character 2' seems to be
minutely faster than 'middle character'.
Interestingly, although multiplying an integer by itself is nearly twice
as fast as squaring it (!), the effect was for some reason almost exactly
cancelled out by the two tells in my script. :-\
>(Incidentally, when the decimal part of the input number is .565, .
>57, .575 or .58, I noticed a few rounding variations between the
>approaches.)
Yes. My effort did better than your original with one of my favourite
test numbers, -321.255, but they were both wrong with, for instance, -
321.575. Your later version seems to be very robust so far. :)
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