Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have this number 0.581183781439, I need to round the number 0.582

I was trying with

SELECT ROUND (0.581183781439, 3)
-------------------------------
0.581000000000

Is it useful ROUND function for this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
366 views
Welcome To Ask or Share your Answers For Others

1 Answer

DECLARE @Test TABLE (Col NUMERIC(38,12));

INSERT  @Test (Col)
SELECT 0.581183781439 
UNION ALL
SELECT 0.5815
UNION ALL
SELECT 0.581883781439
UNION ALL
SELECT -0.581883781439;

SELECT Col AS [Col],
    ROUND(Col, 3) AS StandardRounding_3decimals,
    ROUND(Col, 3, 1) AS Truncation_3decimals,
    FLOOR(Col*1000)/1000 AS RoundDown_3decimals,
    CEILING(Col*1000)/1000  AS RoundUp_3decimals 
FROM @Test;

Results:

Col             StandardRounding_3decimals Truncation_3decimals RoundDown_3decimals RoundUp_3decimals
--------------- -------------------------- -------------------- ------------------- -----------------
0.581183781439  0.581000000000             0.581000000000       0.581000            0.582000
0.581500000000  0.582000000000             0.581000000000       0.581000            0.582000
0.581883781439  0.582000000000             0.581000000000       0.581000            0.582000
-0.581883781439 -0.582000000000            -0.581000000000      -0.582000           -0.581000

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...