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.