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. Visual Basic
  4. Unwanted rounding in a sum !!!!!

Unwanted rounding in a sum !!!!!

Scheduled Pinned Locked Moved Visual Basic
helptutorial
2 Posts 2 Posters 1 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.
  • M Offline
    M Offline
    mixahlos
    wrote on last edited by
    #1

    Ok this is something :mad::mad::mad::mad::mad::mad::mad: The problem I have is that when I'm calculating some values the sum is rounded and i dont want it for example, here is some of my code ******************** code ******************* dim price, totalprice, tax as Long Format TotalPrice, "$#,##0;;\Z\e\r\o" Format Tax, "$#,##0;;\Z\e\r\o" Format Price, "$#,##0;;\Z\e\r\o" Price = 0 For i = 0 To 21 Price = Price + LBLSelPrice(i).Caption Next LblTotal.Caption = Price ' eg 125 Tax = (Price * 0.18) LblTax.Caption = Tax 'equals 22.5, displays fine TotalPrice = Tax + Price LblGenTotal = TotalPrice ' Here it displays 148 instead of 147.50 *********************** code ****************** while debugging I noticed that the problem is not the labels problem but I was watching my variables and I saw that the totalprice var. when I am summarizing the price and the tax vars is rounded. In the labels properties I changed the format to number with 2 decimal points !!! It s not workink, no way !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! :mad::mad::mad::mad::mad::mad: HELP !!! Mike Eco

    Richard DeemingR 1 Reply Last reply
    0
    • M mixahlos

      Ok this is something :mad::mad::mad::mad::mad::mad::mad: The problem I have is that when I'm calculating some values the sum is rounded and i dont want it for example, here is some of my code ******************** code ******************* dim price, totalprice, tax as Long Format TotalPrice, "$#,##0;;\Z\e\r\o" Format Tax, "$#,##0;;\Z\e\r\o" Format Price, "$#,##0;;\Z\e\r\o" Price = 0 For i = 0 To 21 Price = Price + LBLSelPrice(i).Caption Next LblTotal.Caption = Price ' eg 125 Tax = (Price * 0.18) LblTax.Caption = Tax 'equals 22.5, displays fine TotalPrice = Tax + Price LblGenTotal = TotalPrice ' Here it displays 148 instead of 147.50 *********************** code ****************** while debugging I noticed that the problem is not the labels problem but I was watching my variables and I saw that the totalprice var. when I am summarizing the price and the tax vars is rounded. In the labels properties I changed the format to number with 2 decimal points !!! It s not workink, no way !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! :mad::mad::mad::mad::mad::mad: HELP !!! Mike Eco

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      Variables declared as Long cannot hold fractional parts, and will always be rounded.

      Dim Price As Currency, TotalPrice As Currency, Tax as Currency, i As Long
      Price = 0
      For i = 0 To 21
      Price = Price + CCur(LBLSelPrice(i).Caption)
      Next
      LblTotal.Caption = Price
      Tax = (Price * 0.18)
      LblTax.Caption = Tax
      TotalPrice = Tax + Price
      LblGenTotal.Caption = TotalPrice


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      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