EDN Admin
Well-known member
Damn, I`m struggling with converting string to a decimal number. The point is that if i insert a comma in the string, my current culture recognize the string as a full valid decimal number.
If I insert a dot, the decimal delimiter is removed from the decimal number. Examples:
<div style="color:Black;background-color:White; <pre>
stirng str1 = <span style="color:#A31515; "1,2";
<span style="color:Blue; string str2 = <span style="color:#A31515; "1.2";
<span style="color:Blue; decimal d1 = <span style="color:Blue; decimal.Parse(str1); //output <span style="color:Blue; is 1.2 - OK
<span style="color:Blue; decimal d2 = <span style="color:Blue; decimal.Parse(str2); //output <span style="color:Blue; is 12 - <span style="color:Blue; NOT OK
[/code]
----------<br/>
So i was playing around for couple of hours with CultureInfo and NumberFormatInfo classes. In one case I have even suceeded, but I wasn`t satisifed. Why? Because this solution would only work in the cultures similar to mine (in US would not for an instance).
----------
So I would like to do something that will will work any where around the globe. I was thinking to get the current culture and then based on that decide which NumberFormat to use.
Here I will need some help from you guys.
<hr class="sig Mitja
View the full article
If I insert a dot, the decimal delimiter is removed from the decimal number. Examples:
<div style="color:Black;background-color:White; <pre>
stirng str1 = <span style="color:#A31515; "1,2";
<span style="color:Blue; string str2 = <span style="color:#A31515; "1.2";
<span style="color:Blue; decimal d1 = <span style="color:Blue; decimal.Parse(str1); //output <span style="color:Blue; is 1.2 - OK
<span style="color:Blue; decimal d2 = <span style="color:Blue; decimal.Parse(str2); //output <span style="color:Blue; is 12 - <span style="color:Blue; NOT OK
[/code]
----------<br/>
So i was playing around for couple of hours with CultureInfo and NumberFormatInfo classes. In one case I have even suceeded, but I wasn`t satisifed. Why? Because this solution would only work in the cultures similar to mine (in US would not for an instance).
----------
So I would like to do something that will will work any where around the globe. I was thinking to get the current culture and then based on that decide which NumberFormat to use.
Here I will need some help from you guys.
<hr class="sig Mitja
View the full article