473,385 Members | 1,309 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

formats real numbers

Hi!

I'm writing a program that has support for multiple language, so far
swedish and english is requested.

Everything is fine, but the program has to be able to run on computers
with different language settings. It must for example be possible to
run an english version of the program at a computer where the national
settings is keept a Swedish.

The problem occurs when VB formats real numbers, since in Swedish a
comma "," is used as decimal notation and in english a "." is used. So
when running the program in english at a "Swedish computer", the comma
is still used as decimal notation. How can i change the print format
of double's without messing with the computer language settings?

Best regards,
Andreas Lundgren
Jul 17 '05 #1
4 5682
> I'm writing a program that has support for multiple language, so far
swedish and english is requested.

Everything is fine, but the program has to be able to run on computers
with different language settings. It must for example be possible to
run an english version of the program at a computer where the national
settings is keept a Swedish.

The problem occurs when VB formats real numbers, since in Swedish a
comma "," is used as decimal notation and in english a "." is used. So
when running the program in english at a "Swedish computer", the comma
is still used as decimal notation. How can i change the print format
of double's without messing with the computer language settings?


That could be tricky. For example, if you are using a grid-type control,
you may or may not be able to play with the display format depending on
the "robustness" of the grid control. However, if you are using simple
input and output controls, you could do something along these lines. Say
you are taking in input in a TextBox and a UseEnglish flag variable is
set to true. Then you might do something like this after the user
signals to continue...

If UseEnglish Then
NumericVariable = CDbl(Replace(Text1.Text, ".", ","))
End If

You could use CSng depending on the precision you need to work with. As
for Print'ing the result somewhere, you could possibly do this...

If UseEnglish Then
OutputText = Format$(NumericVariable, "<<anyway you want>>")
OutputText = Replace(OutputText, ",", ".")
End If
Print OutputText

Of course, your challenge will be to catch every place input and output
is taking place so that you can splice in this conversion. The key is to
convert from or to the English format immediately after input or
immediately before output. The above assumes no "thousands separators"
will be used. If they will be permitted, then something like this will
be required

If UseEnglish Then
NumericVariable = Replace(Text1.Text, ",", Chr$(1))
NumericVariable = Replace(NumericVariable, ".", ",")
NumericVariable = Replace(NumericVariable, Chr$(1), ".")
End If

with a similar treatment for output.

Rick - MVP

Jul 17 '05 #2
On 20 Jul 2004 06:45:18 -0700, d9****@efd.lth.se (Andreas) wrote:
Hi!

I'm writing a program that has support for multiple language, so far
swedish and english is requested.

Everything is fine, but the program has to be able to run on computers
with different language settings. It must for example be possible to
run an english version of the program at a computer where the national
settings is keept a Swedish.

The problem occurs when VB formats real numbers, since in Swedish a
comma "," is used as decimal notation and in english a "." is used. So
when running the program in english at a "Swedish computer", the comma
is still used as decimal notation. How can i change the print format
of double's without messing with the computer language settings?


Personally I would say don't use any 'locale aware' stuff

But if you are leaching off 3rd party dubious controls you have a
problem.
Jul 17 '05 #3
Thanks,

I feared that would be the only solution. As I work with the number
before printing them, I have to add some code when I print them.
Sometimes the printout is for example a division of two integers, so
there is a lots of hidden places where I must remember to edit...

Thanks anyway!

"Rick Rothstein" <ri************@NOSPAMcomcast.net> wrote in message news:<Vd********************@comcast.com>...
I'm writing a program that has support for multiple language, so far
swedish and english is requested.

Everything is fine, but the program has to be able to run on computers
with different language settings. It must for example be possible to
run an english version of the program at a computer where the national
settings is keept a Swedish.

The problem occurs when VB formats real numbers, since in Swedish a
comma "," is used as decimal notation and in english a "." is used. So
when running the program in english at a "Swedish computer", the comma
is still used as decimal notation. How can i change the print format
of double's without messing with the computer language settings?


That could be tricky. For example, if you are using a grid-type control,
you may or may not be able to play with the display format depending on
the "robustness" of the grid control. However, if you are using simple
input and output controls, you could do something along these lines. Say
you are taking in input in a TextBox and a UseEnglish flag variable is
set to true. Then you might do something like this after the user
signals to continue...

If UseEnglish Then
NumericVariable = CDbl(Replace(Text1.Text, ".", ","))
End If

You could use CSng depending on the precision you need to work with. As
for Print'ing the result somewhere, you could possibly do this...

If UseEnglish Then
OutputText = Format$(NumericVariable, "<<anyway you want>>")
OutputText = Replace(OutputText, ",", ".")
End If
Print OutputText

Of course, your challenge will be to catch every place input and output
is taking place so that you can splice in this conversion. The key is to
convert from or to the English format immediately after input or
immediately before output. The above assumes no "thousands separators"
will be used. If they will be permitted, then something like this will
be required

If UseEnglish Then
NumericVariable = Replace(Text1.Text, ",", Chr$(1))
NumericVariable = Replace(NumericVariable, ".", ",")
NumericVariable = Replace(NumericVariable, Chr$(1), ".")
End If

with a similar treatment for output.

Rick - MVP

Jul 17 '05 #4
> I feared that would be the only solution. As I work with the number
before printing them, I have to add some code when I print them.
Sometimes the printout is for example a division of two integers, so
there is a lots of hidden places where I must remember to edit...


Maybe you could construct a Sub to do the printing and in the Sub do the
Replace operation. If you take the argument ByVal, then you won't have
to worry about preserving the regional setting for the numbers inside
main section of your program. All you would have to do is switch all of
the Print statements you have to the Sub you write. VB's Find/Replace
editing in the IDE should be able to find all of the occurrences of
Print for you.

Rick - MVP

Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Aaron W. West | last post by:
Timings... sometimes there are almost too many ways to do the same thing. The only significant findings I see from all the below timings is: 1) Integer math is generally fastest, naturally....
1
by: Roger | last post by:
I am currently working on an application that is being used mostly in the US but recently has been purchased by several users outside the US, mostly in South America. The application uses an...
4
by: Vig | last post by:
Is scanf or any other function capable of reading numbers in the format 1.2345d-13 where 'd' serves the same role as 'e' usually does in scientific notation? This operation is iterated through...
4
by: Zeng | last post by:
Hi, Is there a way to parse datetime in string with following possible formats into a DateTime object? - MM/DD/YYYY - MM/DD/YY - MM/YY - MM/YYYY This line of code would throw if I pass...
10
by: Pavils Jurjans | last post by:
Hallo, It is know issue that due to the fact that computer has to store the real numbers in limited set of bytes, thus causing a minor imprecision from the decimal value that likely was stored....
20
by: tomerfiliba | last post by:
hey i've been seeing lots of config-file-readers for python. be it ConfigObj (http://www.voidspace.org.uk/python/configobj.html) or the like. seems like a trend to me. i came to this conclusion...
8
by: aarklon | last post by:
hi all, in http://www.c-faq.com/cpp/ifendian.html it is said that integer formats used in pre processor #if expressions are not the same as those will be used at run time. can any one...
2
by: Koliber (js) | last post by:
sorry for my bad english, i hope this group is appriopriate for this question task i am tryin to do is to write code to extract some frames from popular (popular on a windows platform)...
16
by: DirtyHarry | last post by:
Good day everyone. This sounds like a stupid question, but I became just curious yesterday, and I looked up several textbooks. However, no textbooks on computer language (that I have ) mentioned...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.