473,378 Members | 1,607 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,378 software developers and data experts.

Regional independant Format() with dots-comma's

My application populates a ListBox from a .TXT file. In the textfile there
are prices with both dots as well as comma's for decimal indication.
Example:

1234990; xg-tr-45; 1700,50; 0
2662666; hj-54-56; 1565.00; 0
8228880; 30-56-tw; 3295.50; 0
0022339; hs-sa-73; 2975,75; 0
.... etc

The amounts (third column) are used to calculate a total. However, since I
have Dutch regional settings only the comma-seperations can be used for
calculating a correct sum. My system ignores the prices with the decimal
seperated by a dot (.) It is no option to alter the .TXT file.

I tried various options, such as formatting the entries with practically all
the options I could find. One example:

ItemAmount = Format(CSng(ItemAmount), "Currency")

Is there a simple solution for this, besides converting the prices? If
anyone could help, I would gratefully appreciate it.

Nov 20 '05 #1
7 5213
In article <Ov**************@TK2MSFTNGP09.phx.gbl>, Sick wrote:
My application populates a ListBox from a .TXT file. In the textfile there
are prices with both dots as well as comma's for decimal indication.
Example:

1234990; xg-tr-45; 1700,50; 0
2662666; hj-54-56; 1565.00; 0
8228880; 30-56-tw; 3295.50; 0
0022339; hs-sa-73; 2975,75; 0
... etc

The amounts (third column) are used to calculate a total. However, since I
have Dutch regional settings only the comma-seperations can be used for
calculating a correct sum. My system ignores the prices with the decimal
seperated by a dot (.) It is no option to alter the .TXT file.

I tried various options, such as formatting the entries with practically all
the options I could find. One example:

ItemAmount = Format(CSng(ItemAmount), "Currency")

Is there a simple solution for this, besides converting the prices? If
anyone could help, I would gratefully appreciate it.


Here is a little something, though in reverse :) It totals up the
values in an array of strings with mixed values.

Option Strict On
Option Explicit On

Imports System.Globalization

Module Module1

Sub Main()
Dim values() As String = {"1700,5", "1565.00", "3295.50", "2975,75"}
Dim total As Double

Dim nfi As NumberFormatInfo = New NumberFormatInfo
nfi.NumberDecimalSeparator = ","
nfi.NumberGroupSeparator = "."

For Each value As String In values
If value.IndexOf("."c) = -1 Then
total += Convert.ToDouble(value, nfi)
Else
total += Convert.ToDouble(value)
End If
Next

Console.WriteLine(total)
End Sub

End Module

Anyway, might give you a way to go :)
--
Tom Shelton
MVP [Visual Basic]
Nov 20 '05 #2
In article <O3**************@tk2msftngp13.phx.gbl>, Tom Shelton wrote:
In article <Ov**************@TK2MSFTNGP09.phx.gbl>, Sick wrote:
My application populates a ListBox from a .TXT file. In the textfile there
are prices with both dots as well as comma's for decimal indication.
Example:

1234990; xg-tr-45; 1700,50; 0
2662666; hj-54-56; 1565.00; 0
8228880; 30-56-tw; 3295.50; 0
0022339; hs-sa-73; 2975,75; 0
... etc

The amounts (third column) are used to calculate a total. However, since I
have Dutch regional settings only the comma-seperations can be used for
calculating a correct sum. My system ignores the prices with the decimal
seperated by a dot (.) It is no option to alter the .TXT file.

I tried various options, such as formatting the entries with practically all
the options I could find. One example:

ItemAmount = Format(CSng(ItemAmount), "Currency")

Is there a simple solution for this, besides converting the prices? If
anyone could help, I would gratefully appreciate it.

Here is a little something, though in reverse :) It totals up the
values in an array of strings with mixed values.


After thinking about it, thought I better add some comments :)
Option Strict On
Option Explicit On

Imports System.Globalization

Module Module1

Sub Main()
Dim values() As String = {"1700,5", "1565.00", "3295.50", "2975,75"}
Dim total As Double
' Create a NumberFomratInfo object to handle the values
' using the coma as the decimal separator. Need to specify
' both the group separator and the decimal separator or you'll
' get an exception... In your case, you'll want to reverse the
' the values. Dim nfi As NumberFormatInfo = New NumberFormatInfo
nfi.NumberDecimalSeparator = "," ' you use . here
nfi.NumberGroupSeparator = "." ' you use , here

' Now we'll just iterate over the array and
' acumulate the total For Each value As String In values
' If this value doesn't contain a . then
' it uses a comma and we need to use our
' custom numberformat object in the conversion
' otherwise, it's in good old US of A format :) If value.IndexOf("."c) = -1 Then ' you test for ","c
total += Convert.ToDouble(value, nfi)
Else
total += Convert.ToDouble(value)
End If
Next

Console.WriteLine(total)
End Sub

End Module

Anyway, might give you a way to go :)


--
Tom Shelton
MVP [Visual Basic]
Nov 20 '05 #3
Cor
Hi Sick
I did found the solution from Tom nice. But Tom is not Dutch and this is a
normal problem in Holland. We use the US keyboards but there is a dot on the
numpad, while our decimal seperator is a comma. Overlooking it, I see you
are using a listbox where you are entering a textStrings. (For who reads
this beside Sick, there were Dutch keyboards, but they are rarely used).

The only thing I hope we are sure about is that the value field is the 3th
field after the ; So I think the solution can be rough typed not tested
\\\\
dim myStringValues() as String = Split(listboxItem,";")
dim myDoubleValue as double = Cdbl(replace(String(2),".",","))
///

You even can put a control in it to see if it is complete with
if myStringValue.count <> 4 then
' do error
Handling.

I myself would do it on another way and use this or another method to
populate a listview. Would look much nicer.

I hope this helps a little bit?

Cor
Nov 20 '05 #4
In article <eI**************@TK2MSFTNGP10.phx.gbl>, Cor wrote:
Hi Sick
I did found the solution from Tom nice. But Tom is not Dutch and this is a
normal problem in Holland. We use the US keyboards but there is a dot on the
numpad, while our decimal seperator is a comma. Overlooking it, I see you
are using a listbox where you are entering a textStrings. (For who reads
this beside Sick, there were Dutch keyboards, but they are rarely used).


Your right, I'm not Dutch :) But, I'm not sure why my solution won't
work... What am I missing?

--
Tom Shelton
MVP [Visual Basic]
Nov 20 '05 #5
Cor
Hi Tom,

I found it a very nice solution for doing an unstring with the same problem
and I did put it in my snippets. I did not say there is anything wrong with
it.

Then I looked it over again and saw the string was not made.

Therefore I did made an example. And while busy I thought, hell, normaly I
wou ld in this case only do replace the dot for a comma, so let me give that
example also.

And to show the world what problem we always have in Holland with that
numboard with the dot, I added the extra text.

But your example is nice espacialy when this is in a untstring, like I said
in the message to Sick and it stays in my snippets.
:-)
Cor
Nov 20 '05 #6
In article <O0**************@TK2MSFTNGP10.phx.gbl>, Cor wrote:
Hi Tom,

I found it a very nice solution for doing an unstring with the same problem
and I did put it in my snippets. I did not say there is anything wrong with
it.

Then I looked it over again and saw the string was not made.

Therefore I did made an example. And while busy I thought, hell, normaly I
wou ld in this case only do replace the dot for a comma, so let me give that
example also.

And to show the world what problem we always have in Holland with that
numboard with the dot, I added the extra text.

But your example is nice espacialy when this is in a untstring, like I said
in the message to Sick and it stays in my snippets.
:-)
Cor


Ok, I thought maybe it didn't work. I misunderstood. I am not a big
expert in i18n, so I thought maybe I was missing something. Very good
:) I have to ask, isn't it true that most of Europe uses the . and ,
opposite of the US? In other words - US = 1,050.75, Europe = 1.050,75?
Would that make this a common problem all over - or do most people use
special keyboards?

Just curious... I do have a book on the subject for VB6 (it is by
someone you may recognize - http://www.i18nwithvb.com/), but I never
really read it :) I started to, because of a project we were going to
take on - but then the project fell through. I wonder how much would
apply for .NET? I wonder if he will be writing a .NET version?

--
Tom Shelton
MVP [Visual Basic]
Nov 20 '05 #7
Cor
Hi Tom,

Europe is of course more and more one country, but we have a lot of regional
settings, languages and traditions, so I will try to explain as far as I
know it.

In the whole Europe with exception from Britain is used 999.999,99 (we think
the Brittains do it on another way because they do everything else than the
rest, but slowly they are using the more European things like the kilo, the
meter etc. and someday the Euro). I am not sure from Ireland (I think also
like Britain and is this one of the exceptions because normaly they are not
following them, we will hear that from Fergus when he reads this, he is
origonal Irish)

The dot is not always used, in case of your example you will mostly/often
see 1050,75. When it become larger amounts the dot can be used. I think
there is no rule for that.
:) I have to ask, isn't it true that most of Europe uses the . and ,
opposite of the US? In other words - US = 1,050.75, Europe = 1.050,75?
Most European Countries have their own keyboards with some exceptions.
The exception can be because some fools made the regional keyboards so
stupid that the where unusual (that was in Holland and in Poland I thought)
or just because they are never used.

In that case we use the US keyboard with special setting or not. In Holland
they do not, because than you get that rarely used Dutch keyboard. For the
Polish there are more settings, so they can do it because they have a lot of
extra characters in their language.

Most languages have extra characters when you compare it with the English
language. Dutch has that too but not like the German language which has
really one characters more. Dutch has only some "accents" to split words or
to set the tone.

A big wish of every developer in Holland and the Dutch speaking part of
Belgian and I think in all Europe where the US keyboard is used, is to have
the possibility to use the dot on the num pad as a comma, but till now I
never saw that.

Then there are also minimal 2 keyboards designs. Called QWERTY (that is
written on the left side on the 3rd row of the keyboard) and AZERTY.

You find QWERTY on the Latin languages speaking part of Europe. (French,
Italian, Spanisch and Portugese) and in the Slavian language speaking part.
I am only sure for French. There is too the Easern part where Cyrillic
characters are used (Like Creece, Russia, Bulgaria, and Ukraine). I know
nothing about their keyboards.

I am sure of that people who speak the German and French language uses
really there own keyboard, but from Italian and Spain I am not sure and the
same is for the Scandinavians, maybe because they have also a lot of extra
characters.

I think that the main reason why people are using the US keyboards in
Europe, is that they were at start seldom, while people were used already on
the IBM PC US. I know that Poland they switch almost totally from Azerty to
Qwerty. It is very difficult to type on a US keyboard when you are used to
your national language keyboard and visa versa.

I hope this is enough, maybe we get some comments from Fergus Irish and
Herfried German speaking in Austria, Armin from Germany and Jan, who is
definitely from a Scandinavian Country or all others who will learn us
something about this.

:-)

Cor



Would that make this a common problem all over - or do most people use
special keyboards?

Nov 20 '05 #8

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

Similar topics

1
by: nerman | last post by:
Hello I have a problem with the regional settings. I have set the regional settings of the web server to display the numbers in this format 123.456,78 But when I open my web site all number are...
2
by: Cesar Ronchese | last post by:
Hello All! I have a .Net project that, in my machine, the dates are showed in this format: dd/mm/yyyy. But, when I install the project in some customer machines, the date is showed in this...
1
by: Laurence Neville | last post by:
This is regarding a change in the Short Date format under Hebrew Regional Settings, that has caused huge problems in our ASP web application. The change appears to have been introduced sometime...
3
by: Andrew Poulos | last post by:
I'm updating a db in which I have a column of Date/Time data type. The regional settings here for short date are: day / month / full year eg. 28/4/2005 It's easy enough for me to build a string...
2
by: Bob Dydd | last post by:
Hi Everbody Question Changing the regional settings ie. from UK to US AUS etc, Access retains the original currency format that the application was created in. So if an mdb that is written...
1
by: John | last post by:
Hi, The following behavior when using J# vs. C# is really bothering me. When I have the regional settings on my workstation set to a non-US settings (eg: Danish); it seems that J# disregards...
1
by: Cristian | last post by:
Hi, how can I set the decimal separator for an application to be independant from regional settings? Thanks, Cristian crisef@viseotron.ca
7
by: Fred Flintstone | last post by:
I'm writing a VB.Net windows forms application. This line of code: Personal.EffectiveDate = GridRow2.Cells("New Value").Value.ToString.Trim Fails with this error: Cast from string...
16
by: Colmag | last post by:
I've written an application with vb.net 2003 (framework 1.1) which automates a 3rd party viewing/printing application (via an activex control). I've released several versions over the last year...
0
by: SharmaPunit | last post by:
I want to display a date in m/d/yy format. I have written the following lines of code and it is running perfectly till the date format in the regional settings of my computer is set to mm/dd/yyyy or...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.