473,396 Members | 2,039 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,396 software developers and data experts.

CultureInfo problem

Hi,
I have a c# program where I need a numerical float input. Due to the
culture difference, someone is used to type f.ex. 1,3; 2,32 (, comma) while
others use 1.3; 2.32(. point) etc. so the program should accept both
numerical expression.
How can I do it?
--
windsim
Feb 26 '07 #1
4 2263
windsim wrote:
Hi,
I have a c# program where I need a numerical float input. Due to the
culture difference, someone is used to type f.ex. 1,3; 2,32 (, comma) while
others use 1.3; 2.32(. point) etc. so the program should accept both
numerical expression.
How can I do it?
Replace commas with periods in the string, and use CultureInfo.Invariant
when you parse it.

--
Göran Andersson
_____
http://www.guffa.com
Feb 26 '07 #2
windsim <wi*****@discussions.microsoft.comwrote:
I have a c# program where I need a numerical float input. Due to the
culture difference, someone is used to type f.ex. 1,3; 2,32 (, comma) while
others use 1.3; 2.32(. point) etc. so the program should accept both
numerical expression.
How can I do it?
Well, if you know the appropriate CultureInfo to use, pass it to
double.TryParse as the format provider. If you don't, could you just
replace all commas with points first? Note that that would cause a
problem if people start putting commas in for thousands, eg
1,234.45

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 26 '07 #3
Hi,
A universal solution is the best. I try to use:
Decimal data = Decimal.Parse((string)item.val, new
System.Globalization.CultureInfo("en-US") );
but my variable--item.val is object type, if I convert to string it will
lead to error.
does anyone know how to solve it?
--
windsim
"Jon Skeet [C# MVP]" wrote:
windsim <wi*****@discussions.microsoft.comwrote:
I have a c# program where I need a numerical float input. Due to the
culture difference, someone is used to type f.ex. 1,3; 2,32 (, comma) while
others use 1.3; 2.32(. point) etc. so the program should accept both
numerical expression.
How can I do it?

Well, if you know the appropriate CultureInfo to use, pass it to
double.TryParse as the format provider. If you don't, could you just
replace all commas with points first? Note that that would cause a
problem if people start putting commas in for thousands, eg
1,234.45

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 26 '07 #4
windsim <wi*****@discussions.microsoft.comwrote:
A universal solution is the best. I try to use:
Decimal data = Decimal.Parse((string)item.val, new
System.Globalization.CultureInfo("en-US") );
but my variable--item.val is object type, if I convert to string it will
lead to error.
does anyone know how to solve it?
Well, first you need to work out what to parse. Ignore the parsing part
to start with - what *exactly* is item.val?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 26 '07 #5

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

Similar topics

2
by: choyk1 | last post by:
Hi all, I cannot serialize CultureInfo property as below. It invokes InvalidOperationException. public class One { private CultureInfo culture;
1
by: tommys | last post by:
Hi, I thought that using CultureInfo.CurrentUICulture would give me the current date format as set in the OS - but it did not work that way :-( When re-reading the docs I can see why: "Gets the...
0
by: Maileen | last post by:
Hi, I wrote in VB a small application which save old culture info before to change them for running Excel macro. It looks like that : Dim oldCI As System.Globalization.CultureInfo = _...
1
by: rerdavies | last post by:
OS: WIndows Server 2003. Currently logged in user is running with German(German) regional settings. Code fragment: System.Globalization.CultureInfo culture = new...
8
by: G.Ashok | last post by:
Hi, I have created CultureInfo object and specified required digit grouping in it. The one of the overloaded ToString methods of Decimal type has parameters to format the value with required...
2
by: Giorgio | last post by:
I would to format the date in Italian ...(dd/mm/yyyy) I have set an another language in International setting(for test i have set Lettonia) The format date for this nation is yyyy.mm.dd ... I...
4
by: Dirk Behnke | last post by:
How can I start a new process with a different CultureInfo? I have tried already to set the CultureInfo of the thread starting the new process before creating the Process object, but it doesn't...
8
by: Phil Jollans | last post by:
Hi, I am having difficulty overriding the ToString() method of CultureInfo using Visual Studio 2005. Exactly the same code works fine with Visual Studio .NET 2003. What I am doing is adding...
8
by: =?Utf-8?B?T2xpdmllciBHSUw=?= | last post by:
Hello, I try to convert a volume stored as a string value in an XML file into a Decimal object. The volume is stored with comma as decimal separator ("210,12") according to french habits. To be...
0
by: Dilip | last post by:
I ran into a situation at work regarding unicode character encodings and .NET cultures that left me a tad bit confused. I was trying to instantiate a CultureInfo object from a locale identifying...
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: 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: 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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.