Re: dealing with currencies and different locales....



A few quick notes Guy...

a) Not all European countries use "," as a decimal separator. Britain and
Ireland, for instance, use ".", and always will
b) Val ( & Str) is not locale-aware, and will always expect a "." decimal
separator. This can be useful in a few circumstances
c) CDbl will only accept the correct currency representation for your
current locale, e.g. in Britain, CDbl("£10.34") - which is also my salary -
works, but CDbl("$10.34") fails with 'Type mismatch'

Tony Proctor

"G Doucet" <someone@xxxxxxxxxxxxxxx> wrote in message
news:MUpKf.32703$VV4.377318@xxxxxxxxxxxxxxxxxxxxxxxxxx
I'd like to share what I have found today. I'm just wondering if this is
the correct way to deal with currencies. In the past
(like until this morning) I used to use something like this:

Text1.Text = Format(cCOSTA,"#,0.00").
' ...
cCOSTB = Val(Text1.Text)

This would give me problems when I tried to retrieve the value of the text
box. One problem: the Val() function would return 0 if
I included the dollar sign. The other problem occured when I used a
different locale. It turns out that European countries (as
far as I know), will display 10 euros as "10,00" instead of "10.00", -
the decimal point is replaced by a comma. So now Val()
doesn't work because of the comma.

Reading in my VB5 help, I found that I should use CDbl() instead of Val().
This would not only get the correct value, but it would
allow me to include the dollar sign in the example above.

I was still getting some problems with CDbl() however. I would get type
mismatch errors at times when my locale wasn't set to US.
I found out later that it was because I had preset some text boxes with
"0.00" and the CDbl() function was expecting "0,00" - with
the comma.

Besides that, I noticed that in other locales, the dollar sign (or Euro
symbol) is displayed at the right, like "10,00 $". That's
when I realised that the Format function wasn't working well for me.

Finally, I found that I could use the Format() function using a format
name such as:

Text1.Text = Format(cCOSTA, "Currency")

I also found that the best way to preset my text boxes to zero is like
this:

Text1.Text = Format(0, "Currency")

Is there anything else I should know about displaying currencies in text
boxes and then reading them again?

Guy




.



Relevant Pages

  • Re: xlrd+excel determine decimal separator
    ... It's nothing to do with xlrd. ... Excel file and send it to a user of locale B and the ... receiver will see ',' -- as you might expect, locale-specific info is ... decimal separator, ...
    (comp.lang.python)
  • Re: Decimal point or decimal comma
    ... As I understand it, European countries ... The reasons for doing so made excellent sense. ... "Chris Blunt" wrote ... precede a decimal separator). ...
    (uk.finance)
  • Re: Change , to .
    ... Does your locale use the coma for the decimal separator? ... Having a PC that uses the coma as a decimal sperator go to the immediate ... Note how I typed in the dot as a decimal seperator. ...
    (microsoft.public.vb.general.discussion)
  • Re: dealing with currencies and different locales....
    ... Not all European countries use "," as a decimal separator. ... Britain and Ireland, for instance, use ".", and always will ...
    (comp.lang.basic.visual.misc)
  • Re: Newbie help on String conversion needed please
    ... A programming language has it's own conceptual locale, ... format of decimal numbers, ... query will fail in regional locales that use a ',' decimal separator. ...
    (microsoft.public.vb.general.discussion)