[Gambas-user] I create a new function to share
Doriano Blengino
doriano.blengino at ...1909...
Sat Jun 27 08:52:52 CEST 2009
Benoît Minisini ha scritto:
>> 1. i18n says that a "normal" number has no thousand separator; instead a
>> currency ("monetary") has it. Thinking again and again, this could make
>> sense.
>>
>> 2. KDE desktop has its own management. Don't know how and why - perhaps
>> those guys want to run KDE without i18n dependency. Gambas uses much of
>> KDE, but not its locale settings. This again could make sense.
>>
>> 3. Using native Gambas functions there is no way to format a number like
>> a monetary one, without putting the currency symbol in place.
>>
>> 4. Anyway, i18n says that the thousand separator is _nothing_, not a
>> space. Which is different.
>>
>> 5. I *could* modify the relevant file, just to see it overwritten the
>> next time a system update takes place. Anyway, I think that that file is
>> correct.
>>
>> All the things make sense, but I can not believe that one can not format
>> a currency without putting the monetary symbol in. Sounds strange, true?
>>
>> Regards,
>>
>
> Sorry, I didn't understand that you wanted to format a currency value without
> the currency symbol. Strange anyway...
>
It is not strange at all... think at those reports commercials do for
taxes purposes (balance?) after every quarter, or a bank report where
everything reported is money. money, money and always money. Being all
filled with numbers, all of them signifying currency, it is better to
not repeat the "$" or "€" every time - the report is more readable.
To be precise, what I wanted (and failed) to say is a little different.
Often I want to print a number (a quantity of some material, for
example, or a long distance expressed in Km). According to i18n such
number should not have a thousand separator, but it is common practice
to use those separators anyway: try to do a calculation in KCalc - it
will show the separators (without currency symbol).
> As a workaround, you can use the following function:
>
> PRIVATE SUB FormatCurrency(eValue AS Float, sFormat AS String) AS String
>
> DIM sCurr AS String
> DIM sResult AS String
> DIM iPos AS Integer
>
> sCurr = Format(0, "$0")
> sCurr = Replace(sCurr, "0", "")
>
> FOR iPos = 1 TO Len(sFormat)
> IF InStr("0#", Mid$(sFormat, iPos, 1)) THEN BREAK
> NEXT
>
> sResult = Format(eValue, Left(sFormat, iPos - 1) & "$" &
> Mid$(sFormat, iPos + 1))
>
> sResult = Replace(sResult, sCurr, "")
>
> RETURN sResult
>
> END
>
>
I did already solve my problem, but your routine is more general and I
will use it in the future. Thanks and regards.
--
Doriano Blengino
"Listen twice before you speak.
This is why we have two ears, but only one mouth."
More information about the User
mailing list