-- 2 -- Even with this syntax something bothers me.
The passed strCatBSP is assumed to be a number
but the returned one is a string.
I thought we'd already done this one to death, Yvan. ;-)
The input for most of the suggestions discussed should work as either
a number or a string. The output has to be a string, otherwise any
zero padding after the decimal separator would be lost - thus
sacrificing the OP's original aim:
"123.40" as number
--> 123.4
"500.00" as number
--> 500.0
-- 3 -- Used in french config, the script returns a foolish result
History:
tell current application
round -40.000000000001
-40
offset of "." in "-0,4"
0
end tell
Result:
"-123.-0"
because the french decimal separator is not a period as was
explained several times in this thread.
That kinda depends which version (of the many) that you're referring
to. In fact, most of the suggestions accommodated the point that you
made - from about here:
To get a correct behaviour worldwide, the handler need some changes
like this version:
on currency_format for v
set d to (round (v mod 1 * 100)) / 100 as string
set decimalSep to character 2 of (0.0 as string)
(v div 1 as text) & "." & text 1 thru 2 of (d's text ((offset of
decimalSep in d) + 1) thru -1 & "00")
end currency_format
I'm afraid that this approach still suffers from some of the rounding
anomalies discussed here:
I'm pretty sure that most of the suggestions from that point on
produced generally more reliable results (although I haven't tested
every variation exhaustively). Take your pick - but not from the
earlier efforts. ;-)