Re: Decimal commas instead of decimal points



Don't mix the locale-aware functions (CStr, CDbl, etc) with the
non-locale-aware functions (e.g. Val, Str) on the same data. Use the
appropriate one depending on whether you want the localised decimal
separator (e.g. if the end-user will see it) or a fixed "." separator (e.g.
if the data is private to the application and may need to be portable across
locales).

If you mix them then you'll run into the difficulties you mentioned.

Also, if you're reading data values with Input # then make sure it was
originally written with Write # (not Print #). Like Val/Str, these
statements always use "." as the decimal separator, and always use "," as
the field separator. As long as you use the correct pair of statements
together than everything should work fine

Tony Proctor

"A. Bulsari" <invalid.user@xxxxxx> wrote in message
news:g7hjad$t47@xxxxxxxxxxxxxx
In article <g7f6j5$20n$1@xxxxxxxxxxxxxxxxxxxxxx>,
Tony Proctor <tony_proctor@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
When you format a decimal number (e.g. with CStr or Format$), VB
automatically uses the correct decimal-point character for your locale

The trouble with this is that it will write commas into files, and
then when I try to read the file, it won't be able to. Or is there a
simple way to make Visual Basic also read 2,5 from a text file as two
and a half? A bad alternative would be to write the file in binary
format, but that makes it impossible for humans to read and modify.


Similarly, when you try to decode a textual representation of a number
(e.g.
with CSng or CDbl) then it automatically expect the correct decimal-point
character

Hence, there should be no hard work involved

I am now wondering if I should change the code in hundreds (dozens?)
of places from Val(Text**) to CSng(Text**). This should work in
English as well as European locales.


Note that the VB language (i.e. what you program with) always uses "." and
never uses ",". This is sometimes called the "programming locale". Make
sure
you don't confuse the language definition with what a VB application does

Incidentally, the Str function always formats a decimal number with ".",
and
the Val function always expects ".". These alternatives to CStr and CDbl
are
the only two VB functions that don't honour the current locale. I prefer
to
view these as "honouring the programming locale" and they can be useful
when
manipulating data files independently of the locale.

Sorry I did not understand this completely. Can I read a text file with
numbers
(and few strings) earlier written by Visual Basic with commas using CStr
and
CSng/CDbl on text picked up by Input #1, length, width, fraction assuming
I would
have to Dim length as string instead of single?


Tony Proctor


Thanks for your input.

With kind regards,

A. Bulsari

<invalid.user@xxxxxx> wrote in message news:g7e557$pc@xxxxxxxxxxxxxx
Many people in Europe use decimal commas instead of decimal points.
How do you deal with this problem? I suspect Visual Basic 6.0 might
know it should read numbers with commas, but it does not seem to be
trivial.

This problem occurs in text boxes as well as in reading and writing
text files.

With kind regards,
A. Bulsari


.



Relevant Pages

  • Re: Strange behaviour of Str$
    ... but I doubt that it would affect Str$() ... > Public Function CStr(A$, B$) As Object ... > - but using locale aware stuff is asking for trouble ... ... at the presentation layer which use our own formatting routines. ...
    (microsoft.public.vb.general.discussion)
  • Re: Decimal commas instead of decimal points
    ... When you format a decimal number, ... automatically uses the correct decimal-point character for your locale ... with CSng or CDbl) then it automatically expect the correct decimal-point ... the only two VB functions that don't honour the current locale. ...
    (comp.lang.basic.visual.misc)
  • Re: Decimal commas instead of decimal points
    ... automatically uses the correct decimal-point character for your locale ... The trouble with this is that it will write commas into files, ... with CSng or CDbl) then it automatically expect the correct decimal-point ... the only two VB functions that don't honour the current locale. ...
    (comp.lang.basic.visual.misc)
  • Re: Parsing a string format
    ... Then use Round to limit the number of decimal places. ... I think CDbl would be better to use than Val. ... locale where the dot is used for the decimal point. ... where the comma is used as the decimal point, then Val would not work as ...
    (microsoft.public.vb.winapi)
  • Re: Parsing a string format
    ... Then use Round to limit the number of decimal places. ... I think CDbl would be better to use than Val. ... Locale then it will not work at all ... If I understand your objection correctly, then I should clarify my response ...
    (microsoft.public.vb.winapi)