473,413 Members | 1,801 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,413 software developers and data experts.

Decimal type representation

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
3 3943
"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Batista, Facundo | last post by:
Here I send it. Suggestions and all kinds of recomendations are more than welcomed. If it all goes ok, it'll be a PEP when I finish writing/modifying the code. Thank you. .. Facundo
5
by: Batista, Facundo | last post by:
I'm proud to announce that the PEP for Decimal Data Type is now published under the python.org structure: http://www.python.org/peps/pep-0327.html This wouldn't has been possible without the...
17
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number....
7
by: hana1 | last post by:
Hello experts, I used to program in C/C++ and now switched to Java. I am having a difficulty that I need your help with. How can I limit a double variable to hold 2 decimal points only? Say I...
15
by: Kay Schluehr | last post by:
I wonder why this expression works: >>> decimal.Decimal("5.5")**1024 Decimal("1.353299876254915295189966576E+758") but this one causes an error 5.5**1024 Traceback (most recent call...
14
by: dharmdeep | last post by:
Hi friends, I need a sample code in C which will convert a Hexadecimal number into decimal number. I had written a code for that but it was too long, I need a small code, so request u all to...
1
by: jmarr02s | last post by:
I am trying to change my Amount column Data Type from Integer to Decimal (precision 9 digits, scale 3, that is 6 digits to the left of decimal and 3 digits to the right of decimal. Here is the...
10
by: cmdolcet69 | last post by:
Public ArrList As New ArrayList Public bitvalue As Byte() Public Sub addvalues() Dim index As Integer ArrList.Add(100) ArrList.Add(200) ArrList.Add(300) ArrList.Add(400) ArrList.Add(500)
10
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places?...
9
by: Elroy Flynn | last post by:
Decimal a = 42.485M; Decimal b = 48M; Decimal c = a / b; Console.WriteLine(c.ToString()); gives the result 0.8851041666666666666666666667 The correct, exact answer is .885. I know that...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.