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 21 Jun 2006, at 21:01, Nigel Garvey wrote:

I guessed you'd be having a go at improving it. :-)

I can always do with the exercise, Nigel. ;-)

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

I tested the 'known position vs. middle' thing on the basis that determining the middle item might involve some kind of internal division. Whether or not that's the reason for the slight difference, a direct positional reference (where the position is known) seems preferable. (That said, 'middle' beats calculating the position of an object's middle element, and then extracting the value.)


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

Yeah. Even a tell takes a toll, I guess. ;-)

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

Encouraging. And with a little shuffling, we can take advantage of both a multiplication and a single tell:


------------------

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


currency_format for -321.255

--> "-321,26" / "-321.26" (* depending on local currency format *)

------------------

:-)

---
kai


_______________________________________________ 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>)



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.