Loading ...

Rounding trouble in C#

Who is online?  0 guests and 0 members
home  »  forums   »  asp.net topics   »  getting started / general asp.net   » Rounding trouble in C#

Rounding trouble in C#

Posts under the topic: Rounding trouble in C#

Posted: 7/7/2011

Lurker 360  points  Lurker
  • Joined on: 6/5/2011
  • Posts: 51

In some cases my TaxTxtBox displays a number that has no remainder.  When my TotPriceTxtBox has a value with no remainder it still displays to the 100th place "34.00".  Then in TextBox1 it truncates the zeros. I need the TaxTxtBox and Textbox1 to diplay zeros to the 100th place when the is no remainder. I.E. keeping it in a money format. I tried using Decimal instead of double but I get an error saying that you cannot apply the *,+ operand to a Decimal or Doudle.  Here's my code:

 protected void EnterBtn_Click(object sender, ImageClickEventArgs e)
        {
            Decimal res = Decimal.Parse(PriceTxtBox.Text);
            res = res * Decimal.Parse(QtyTxtBox.Text);
            TotPriceTxtBox.Text = res.ToString();

            if (TotPriceTxtBox != null)
            {
                Double rs = Double.Parse(TotPriceTxtBox.Text);
                rs = (rs * (.070)) + Double.Parse(TotPriceTxtBox.Text);

                Double ts = (rs * (.070));
                Double tt = ts + Double.Parse(TotPriceTxtBox.Text);
                Double output = Math.Round(rs, 2);
                Double output2 = Math.Round(ts, 2);
                Double output3 = Math.Round(tt, 2);

                TextBox1.Text = output3.ToString();
                TaxTxtBox.Text = output2.ToString();
            }


Page 1 of 1 (1 items)