dealing with currencies and different locales....



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

  • Passing format to variable Part 2
    ... I am passing a currenct number format to a variable and using applying ... If the currency chosen equals one of five specific ... currencies I pass one of 5 specific formats to a variable. ... variable "Currencies" into the format string. ...
    (microsoft.public.excel.programming)
  • Re: Passing format to variable Part 2
    ... string in order to get it into a number format. ... If the currency chosen equals one of five specific ... > currencies I pass one of 5 specific formats to a variable. ...
    (microsoft.public.excel.programming)
  • What is the Delphi solution for Internationalization?
    ... Regional location, localization, etc (currencies, date format, etc, time ... zones) for Delphi? ...
    (borland.public.delphi.non-technical)
  • Datagrid formatting
    ... I need to set the format of a column for currencies but ... when I set the dataformatstring to "" i get a dollar ... and also how can i right justify the ...
    (microsoft.public.dotnet.framework.aspnet)
  • =?Utf-8?Q?Re:_HOW_DO_I_FORMAT_A_CELL_TO_CO?= =?Utf-8?Q?ME_UP_WITH_=E2=82=AC_=C2=A3_$?=
    ... Hi BAZZA, ... > i have a spread sheet with different currencies and I want to know if ... > i can format one column so that the different currency symbol comes ...
    (microsoft.public.excel.worksheet.functions)