Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Simple calculation problem with decimal value drivin me NUTS!!!!

Simple calculation problem with decimal value drivin me NUTS!!!!

Scheduled Pinned Locked Moved C#
helpmobile
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ASGill
    wrote on last edited by
    #1

    im trying to multiply some numbers num1 is a normal integer,(1,2,3....) and num2 is a decimal number(0.23,1.00,3.00....) im having problems multiplying them, i've done it different ways sometimes i get a 0 in the total textbox or this error : Input String was not in a correct format. Can somebody help me out to rectify this problem. if(Pharma.Rows.Count != 0) { string Tablet = (string) Pharma.Rows[0][0]; decimal num2 = Convert.ToDecimal(Tablet); MessageBox.Show(num2.ToString()); //0.23 int num3 = Convert.ToInt32(num2); int num1 = Int32.Parse(txtQuantity.Text); MessageBox.Show(num1.ToString()); //12 total = num1 * num3; decimal total1 = Convert.ToDecimal(total); MessageBox.Show(total.ToString()); //2.76 txtMedTotal.Text = total.ToString(); } else { MessageBox.Show("The Patient has yet to be processed","Information"); } this code is givin me back a result of 0...when it should be 2.76 :doh: :doh: :doh: im three times confused now!

    M 1 Reply Last reply
    0
    • A ASGill

      im trying to multiply some numbers num1 is a normal integer,(1,2,3....) and num2 is a decimal number(0.23,1.00,3.00....) im having problems multiplying them, i've done it different ways sometimes i get a 0 in the total textbox or this error : Input String was not in a correct format. Can somebody help me out to rectify this problem. if(Pharma.Rows.Count != 0) { string Tablet = (string) Pharma.Rows[0][0]; decimal num2 = Convert.ToDecimal(Tablet); MessageBox.Show(num2.ToString()); //0.23 int num3 = Convert.ToInt32(num2); int num1 = Int32.Parse(txtQuantity.Text); MessageBox.Show(num1.ToString()); //12 total = num1 * num3; decimal total1 = Convert.ToDecimal(total); MessageBox.Show(total.ToString()); //2.76 txtMedTotal.Text = total.ToString(); } else { MessageBox.Show("The Patient has yet to be processed","Information"); } this code is givin me back a result of 0...when it should be 2.76 :doh: :doh: :doh: im three times confused now!

      M Offline
      M Offline
      MasudM
      wrote on last edited by
      #2

      Hi Where you Put int num3 = Convert.ToInt32(num2); Num2 turns to 0.because it has 0 as integer part.you better convert Num1 to Decimal !! or just Multiply Nme1 and Num2

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups