Decimal type representation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?UGFvbG8=?=

    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
  • Alberto Poblacion

    #2
    Re: Decimal type representation

    "Paolo" <Paolo@discussi ons.microsoft.c omwrote in message
    news:1BD88DB0-C988-4DB4-A6F2-BD9BC244DFA5@mi crosoft.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(T extBox1.Text);

    Then change it into:

    CultureInfo ci = new CultureInfo("en-US");
    decimal d = decimal.Parse(T extBox1.Text, ci);

    This will always use the period as a decimal separator, regardles of the
    CurrentCulture setting.


    Comment

    • =?Utf-8?B?UGFvbG8=?=

      #3
      Re: Decimal type representation

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

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

      The code capturing transAmount is:

      private void msktxtbxAmount_ TypeValidationC ompleted(object sender,
      TypeValidationE ventArgs e)
      {
      if (!e.IsValidInpu t)
      MessageBox.Show ("Invalid amount", "Error",
      MessageBoxButto ns.OK);
      else
      transAmount = (decimal)e.Retu rnValue; <<<<<<<
      }

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



      "Alberto Poblacion" wrote:
      "Paolo" <Paolo@discussi ons.microsoft.c omwrote in message
      news:1BD88DB0-C988-4DB4-A6F2-BD9BC244DFA5@mi crosoft.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(T extBox1.Text);
      >
      Then change it into:
      >
      CultureInfo ci = new CultureInfo("en-US");
      decimal d = decimal.Parse(T extBox1.Text, ci);
      >
      This will always use the period as a decimal separator, regardles of the
      CurrentCulture setting.
      >
      >
      >

      Comment

      • =?Utf-8?B?UGFvbG8=?=

        #4
        Re: Decimal type representation

        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(Austral ia).
        >
        I have also: msktxtbxAmount. ValidatingType = typeof(System.D ecimal);
        >
        The code capturing transAmount is:
        >
        private void msktxtbxAmount_ TypeValidationC ompleted(object sender,
        TypeValidationE ventArgs e)
        {
        if (!e.IsValidInpu t)
        MessageBox.Show ("Invalid amount", "Error",
        MessageBoxButto ns.OK);
        else
        transAmount = (decimal)e.Retu rnValue; <<<<<<<
        }
        >
        Perhaps I should divide transAmount by 100 (not 10,000!) before I update the
        table?
        >
        >
        >
        "Alberto Poblacion" wrote:
        >
        "Paolo" <Paolo@discussi ons.microsoft.c omwrote in message
        news:1BD88DB0-C988-4DB4-A6F2-BD9BC244DFA5@mi crosoft.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(T extBox1.Text);

        Then change it into:

        CultureInfo ci = new CultureInfo("en-US");
        decimal d = decimal.Parse(T extBox1.Text, ci);

        This will always use the period as a decimal separator, regardles of the
        CurrentCulture setting.

        Comment

        Working...