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. Database & SysAdmin
  3. Database
  4. Formula

Formula

Scheduled Pinned Locked Moved Database
databasehelpquestion
5 Posts 3 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.
  • S Offline
    S Offline
    ScottM1
    wrote on last edited by
    #1

    Hallo all I'm having a problem with some data that I've taken from SQL and copied into an Excel spreadsheet. Please try this and type the following into these cells:

    A1 : -982.21
    B1 : 908.66
    C1 : -73.55
    D1 : =IF(A1+B1=C1,"Correct","Incorrect")

    D1 shows "incorrect" which doesn't make sense since A1 + B1 does equal C1. This happens on a couple of rows, I've checked and they should show correct. I have also tried using the SUM function instead of adding A1+B1 and I even tried (IF C1-B1=A1) but it didn't work either. I have formatted the columns as decimal numbers. Am I missing something really simple here? Any clues would be appreciated Thanks

    There are 10 types of people in the world, those who understand binary and those who dont.

    C M 2 Replies Last reply
    0
    • S ScottM1

      Hallo all I'm having a problem with some data that I've taken from SQL and copied into an Excel spreadsheet. Please try this and type the following into these cells:

      A1 : -982.21
      B1 : 908.66
      C1 : -73.55
      D1 : =IF(A1+B1=C1,"Correct","Incorrect")

      D1 shows "incorrect" which doesn't make sense since A1 + B1 does equal C1. This happens on a couple of rows, I've checked and they should show correct. I have also tried using the SUM function instead of adding A1+B1 and I even tried (IF C1-B1=A1) but it didn't work either. I have formatted the columns as decimal numbers. Am I missing something really simple here? Any clues would be appreciated Thanks

      There are 10 types of people in the world, those who understand binary and those who dont.

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      Rounding errors in the calculation are probably the cause. I'd imagine that excel uses decimal numeric type because it is used so much for financial calculations, while the FLOAT type in the database is just that.


      Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... * Reading: Developer Day 5 Ready to Give up - Your help will be much appreciated. My website

      S 1 Reply Last reply
      0
      • C Colin Angus Mackay

        Rounding errors in the calculation are probably the cause. I'd imagine that excel uses decimal numeric type because it is used so much for financial calculations, while the FLOAT type in the database is just that.


        Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... * Reading: Developer Day 5 Ready to Give up - Your help will be much appreciated. My website

        S Offline
        S Offline
        ScottM1
        wrote on last edited by
        #3

        I think you're right. I used the SUM function on -982.21 and 908.66. I then increased the decimal places on the answer cell to 25 and I saw this -73.5500000000001000000000000 The previous values don't have anything after their first 2 decimal places so I don't know where that 1 is coming from. Will make a plan though. Thanks for your help ;)

        There are 10 types of people in the world, those who understand binary and those who dont.

        1 Reply Last reply
        0
        • S ScottM1

          Hallo all I'm having a problem with some data that I've taken from SQL and copied into an Excel spreadsheet. Please try this and type the following into these cells:

          A1 : -982.21
          B1 : 908.66
          C1 : -73.55
          D1 : =IF(A1+B1=C1,"Correct","Incorrect")

          D1 shows "incorrect" which doesn't make sense since A1 + B1 does equal C1. This happens on a couple of rows, I've checked and they should show correct. I have also tried using the SUM function instead of adding A1+B1 and I even tried (IF C1-B1=A1) but it didn't work either. I have formatted the columns as decimal numbers. Am I missing something really simple here? Any clues would be appreciated Thanks

          There are 10 types of people in the world, those who understand binary and those who dont.

          M Offline
          M Offline
          Michael Potter
          wrote on last edited by
          #4

          If you haven't solved it already - Try:

          =IF(ROUND(A1+B1-C1,5)=0,"Correct","Incorrect")
          
          S 1 Reply Last reply
          0
          • M Michael Potter

            If you haven't solved it already - Try:

            =IF(ROUND(A1+B1-C1,5)=0,"Correct","Incorrect")
            
            S Offline
            S Offline
            ScottM1
            wrote on last edited by
            #5

            Thanks, I already made SQL do the decision and that works. I tried your formula though and it works great. Thanks Scott

            There are 10 types of people in the world, those who understand binary and those who dont.

            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