Hi Luis,
RE: "Simulating CEILING and FLOOR with different lengths"
The following did not return expected results (i.e. the results you provided in your article).
IF object_id('tempdb..#Decimals', 'U') IS NOT NULL
DROP TABLE #Decimals;
CREATE TABLE #Decimals(
OriginalValue decimal(10,4)
);
INSERT INTO #Decimals
VALUES
(3.23),
(3.76),
(3.15),
(3.5),
(-2.34),
(-2.89),
(-2.25),
(-2.5) ,
(-2.2)
;
DECLARE @Length int = -1,
@10 float = 10;
SELECT OriginalValue,
--1st Option
FLOOR( OriginalValue*POWER(@10,@Length))/POWER(@10,@Length) SimulatingFloor,
CEILING(OriginalValue*POWER(@10,@Length))/POWER(@10,@Length) SimulatingCeiling,
--2nd Option
ROUND(OriginalValue-(.49*POWER(@10,-@Length)),@Length) SimulatingFloor2,
ROUND(OriginalValue+(.49*POWER(@10,-@Length)),@Length) SimulatingCeiling2
FROM #Decimals;
I got these results instead:
OriginalValueSimulatingFloorSimulatingCeilingSimulatingFloor2SimulatingCeiling2
3.2300 0 10 0 10
3.7600 0 10 0 10
3.1500 0 10 0 10
3.5000 0 10 0 10
-2.3400 -10 0 -10 0
-2.8900 -10 0 -10 0
-2.2500 -10 0 -10 0
-2.5000 -10 0 -10 0
-2.2000 -10 0 -10 0
What am I missing?
Please clarify.
Thank you.