Welcome to MSSQL Forum!
MSSQL Forum - Discussions about Microsoft SQL Server

You are currently viewing our community forums as a guest user. Sign up or
Having an account grants you additional privileges, such as creating and participating in discussions.

Round error

Discussion in 'General' started by Johnny JUNG, Apr 30, 2015.

  1. Johnny JUNG

    Johnny JUNG New Member

    Hi... I'm making some fomulation. When I tried to execute this one, I thought it should be number 4..... but it is 3.... is there anyone who can help me?

    SELECT ROUND(CAST((ROUND(CAST(80.0-(CAST(SUBSTRING('01:20.70',1,CHARINDEX(':', '01:20.70') -1) * 60 AS FLOAT)
    + (CAST(SUBSTRING('01:20.70',4,4)AS FLOAT)))AS FLOAT),1)/0.2)*-1 AS FLOAT),0)
  2. ccordes

    ccordes New Member

    Looks to me like you have multiplied by 60 before you cast as FLOAT.
    I didn't see it until I broke down your select like this - (I find it helpful when there are more then 3 pairs of () involved)
    Try this -
    (CHARINDEX(':', '01:20.70') -1))AS FLOAT) * 60
    + (CAST(SUBSTRING('01:20.70',4,4)AS FLOAT)))AS FLOAT),1)/0.2)*-1 AS FLOAT),0)

Share This Page

Sponsored link: