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. float type data problem

float type data problem

Scheduled Pinned Locked Moved Database
databasesql-serversysadminhelp
3 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.
  • V Offline
    V Offline
    vuthaianh
    wrote on last edited by
    #1

    Hi all, I've got a problem when manipulating on float type data, I'm working on SQL Server 2005. Here is the code: DECLARE @First float, @Second float, @Third float SET @First = 1.22 SET @Second = 2.72 SET @Third = 3.94 SELECT @First + @Second - @Third The result is "4.44089209850063E-16" instead "0" I can't understand this situation Thanks a lot

    K M 2 Replies Last reply
    0
    • V vuthaianh

      Hi all, I've got a problem when manipulating on float type data, I'm working on SQL Server 2005. Here is the code: DECLARE @First float, @Second float, @Third float SET @First = 1.22 SET @Second = 2.72 SET @Third = 3.94 SELECT @First + @Second - @Third The result is "4.44089209850063E-16" instead "0" I can't understand this situation Thanks a lot

      K Offline
      K Offline
      Krish KP
      wrote on last edited by
      #2

      Use Decimal or Numeric data types. if you are looking for fixed decimal places. float and real are represented using scientific notation. In your case you have to use Decimal or Numeric

      Regards KP

      1 Reply Last reply
      0
      • V vuthaianh

        Hi all, I've got a problem when manipulating on float type data, I'm working on SQL Server 2005. Here is the code: DECLARE @First float, @Second float, @Third float SET @First = 1.22 SET @Second = 2.72 SET @Third = 3.94 SELECT @First + @Second - @Third The result is "4.44089209850063E-16" instead "0" I can't understand this situation Thanks a lot

        M Offline
        M Offline
        Mark Churchill
        wrote on last edited by
        #3

        Yeah floating point arithmetic isn't ever exact. 4.4 * 10^-16 is so small its pretty much zero anyway - close enough! ;)

        Mark Churchill Director Dunn & Churchill Free Download:
        Diamond Binding: The simple, powerful, reliable, and effective data layer toolkit for Visual Studio.

        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