Round error

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)
 

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 -
SELECT
ROUND(
CAST(
(
ROUND(
CAST(
80.0-(
CAST(
SUBSTRING('01:20.70',1,
(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)
 
Top