[Gambas-user] I create a new function to share
kobolds
kobolds at ...2041...
Sat Jun 27 10:16:10 CEST 2009
Doriano Blengino wrote:
>
> 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."
>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
>
try use formatx .
1. to not print currency sign
formatx(9123.12 , "@n9.2") ---> 9,123.12
2. to print currency sign just put the currency sign between (~)
formatx(9123.12 , "@n~€ ~9.2") ---> € 9,123.12
formatx(9123.12 , "@n9.2~ €~") ---> 9,123.12 €
as you can see you only need to type 1 line
--
View this message in context: http://www.nabble.com/I-create-a-new-function-to-share-tp24216805p24231246.html
Sent from the gambas-user mailing list archive at Nabble.com.
More information about the User
mailing list