laika222
11/4/2016 - 7:12 PM

ROUND(column,# of decimal places) in a SELECT statment takes the values and rounds them in the results. For instance, if you use ROUND(Pric

ROUND(column,# of decimal places) in a SELECT statment takes the values and rounds them in the results. For instance, if you use ROUND(Price,1), it will take the decimals from the Price column and round them to one decimal place. ROUND(Price,0) will round to the nearest dollar. FLOOR() rounds down to nearest integer, CEIL() rounds up to nearest integer. TRUNCATE() cuts a decimal off after a certain number of places without rounding.

-- ROUND(), ROUNDS TO NEAREST INTEGER OR DECMIAL PLACE (NUMBER OF DECIMALS INDICATED BY NUMBER AFTER THE COMMA)
SELECT Price, ROUND(Price,1) AS RoundedPrice
FROM products1; 

-- FLOOR(), ROUNDS DOWN TO NEAREST INTEGER
SELECT Price, FLOOR(Price) AS RoundedPrice
FROM products1; 

-- CEIL(), OR CEILING, ROUNDS UP TO NEAREST INTEGER
SELECT Price, CEIL(Price) AS RoundedPrice
FROM products1; 

-- TRUNCATE(), CUTS A NUMBER OFF AFTER A CERTAIN NUMBER OF DECIMAL PLACES, BUT DOES NOT ROUND
SELECT TRUNCATE(Price,1)
FROM products1;