By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,836 Members | 2,097 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,836 IT Pros & Developers. It's quick & easy.

Decimal type representation

P: n/a
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.

Thanks
Nov 9 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"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.
Nov 9 '08 #2

P: n/a
Alberto: I'm capturing transAmount via a MaskedTextbox whose mask is
$99,999.00 and for which the culture is set to English(Australia).

I have also: msktxtbxAmount.ValidatingType = typeof(System.Decimal);

The code capturing transAmount is:

private void msktxtbxAmount_TypeValidationCompleted(object sender,
TypeValidationEventArgs e)
{
if (!e.IsValidInput)
MessageBox.Show("Invalid amount", "Error",
MessageBoxButtons.OK);
else
transAmount = (decimal)e.ReturnValue; <<<<<<<
}

Perhaps I should divide transAmount by 100 (not 10,000!) before I update the
table?

"Alberto Poblacion" wrote:
"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.
Nov 9 '08 #3

P: n/a
Yes, division by 100 gives me 51.09 in the table.

"Paolo" wrote:
Alberto: I'm capturing transAmount via a MaskedTextbox whose mask is
$99,999.00 and for which the culture is set to English(Australia).

I have also: msktxtbxAmount.ValidatingType = typeof(System.Decimal);

The code capturing transAmount is:

private void msktxtbxAmount_TypeValidationCompleted(object sender,
TypeValidationEventArgs e)
{
if (!e.IsValidInput)
MessageBox.Show("Invalid amount", "Error",
MessageBoxButtons.OK);
else
transAmount = (decimal)e.ReturnValue; <<<<<<<
}

Perhaps I should divide transAmount by 100 (not 10,000!) before I update the
table?

"Alberto Poblacion" wrote:
"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.

Nov 9 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.