views:

544

answers:

1

I'm reading a decimal value from textbox1 and need to insert it to an decimal field in my database.

I having a trouble with "," and "." so first I'm replacing ","s with "." But unfortunately If I enter 1.34 in textbox, it becomes 134.00 in db.

string text = textBox1.Text;
text = text.Replace(",", ".");
decimal total = decimal.Parse(text);

how can I solve this issue?

+1  A: 

What about:

CultureInfo en_us = new CultureInfo("en-US");
decimal value = Decimal.Parse(text, en_us);
Rubens Farias
when it was 1.6 in textbox value after replacing, after decimal.parse value is becoming 16
Henry
No CultureInfo. How can set this settings ?
Henry
This will fail on some languages. See http://www.codinghorror.com/blog/archives/001075.html
Am
Sorry but;string text = textBox_BirimFiyat.Text; decimal birim_fiyat = decimal.Parse(text.Replace(",","."), new System.Globalization.CultureInfo("tr-TR"));still after parsing, 13.4 value becomes 134 :(
Henry
I can't understand where is the problem. decimal birim_fiyat = decimal.Parse(text, new System.Globalization.CultureInfo("en-us"));while text is 13.45 birim_fiyat becomes 1345.00 as I set in my field in db.
Henry
hmm, can you inspect that value _before_ arrive on database?
Rubens Farias
it is 13,5 in db.
Henry
so do we finish? I'm missing something?
Rubens Farias
yes we finished. thanks a lot.
Henry