"Paolo" <Pa***@discussions.microsoft.comwrote in message
news:1B**********************************@microsof t.com...
>I have a table column of SQL smallmoney type which I am updating via a form
input field defined as decimal.
If I enter, say, 51.09 via the decimal input field (representing $51.09),
this is
displayed as 5109.0000 when I view the table data.
I'm not sure why 4 decimal places are being shown, and how would I get the
table data to represent the input i.e. 51.09? I don't want to have to
divide
by 10,000
every time I want to display data or do calculations.
Most probably you have fallen into a decimal separator problem. You may
have your client environment set to interpret the comma as a decimal
separator and the dot as a thousands separator, but the data you are keying
in follows the opposite criterion. If you enter "51.09" but the dot is set
to be the thousands separator, you get "5109".
Follow your code carefully, and find out the point at which you are doing
the conversion from text into decimal. Then ensure that you are using the
correct Globalization to match the format in which the numbers are being
entered.
For instance, if you are entering your "51.09" into TextBox1 and you are
converting into decimal like this:
decimal d = decimal.Parse(TextBox1.Text);
Then change it into:
CultureInfo ci = new CultureInfo("en-US");
decimal d = decimal.Parse(TextBox1.Text, ci);
This will always use the period as a decimal separator, regardles of the
CurrentCulture setting.