ROUND CEIL FLOOR
In this page:
ROUND(number[, decimal_places])
CEIL(number)
FLOOR(number)
ROUND से Numbers Round करना
ROUND default रूप से एक decimal value को सबसे नज़दीकी whole number तक adjust करता है, या अगर आप एक दूसरा argument pass करें तो decimal places की एक specific संख्या तक, इसे prices, averages, और ratings के लिए general-purpose rounding tool बनाते हुए।
उदाहरण: Rounding Numbers with ROUND
SELECT ROUND(4.567) AS whole, ROUND(4.567, 1) AS one_decimal;
CEIL से Round Up करना
CEIL हमेशा एक number को अगले integer तक round up करता है, भले ही decimal हिस्सा tiny हो — 2.01 3 बन जाता है। यह तब उपयोगी है जब आपको एक guaranteed minimum चाहिए, जैसे items की एक partial quantity भेजने के लिए कितनी full boxes चाहिए calculate करना।
उदाहरण: Rounding Up with CEIL
SELECT CEIL(2.01) AS boxes_needed;
FLOOR से Round Down करना
FLOOR हमेशा नीचे अगले integer तक round करता है चाहे decimal round up होने के कितना भी करीब हो, जो billing time के completed पूरे घंटे calculate करने जैसी situations में fit होता है जहाँ एक partial hour count नहीं होना चाहिए।
उदाहरण: Rounding Down with FLOOR
SELECT FLOOR(3.9) AS full_hours;
ROUND के साथ Negative Decimal Places
ROUND अपने decimal-place argument के लिए negative numbers accept करता है, जो fractional digits के बजाय सबसे नज़दीकी दस, सौ, या हज़ार तक round करता है — एक summary report के लिए sales figures को सबसे नज़दीकी हज़ार तक round करने के लिए handy।
उदाहरण: Negative Decimal Places with ROUND
SELECT ROUND(45678, -3) AS rounded_to_thousand;
Tables में Math Functions इस्तेमाल करना
ये functions सीधे एक SELECT statement के अंदर table columns पर काम करते हैं, इसलिए आप database में actually stored precise values कभी बदले बिना users को clean, rounded prices या ratings present कर सकते हैं।
उदाहरण: Using Math Functions in Tables
CREATE TABLE products (id INT, price DECIMAL(10,4));
INSERT INTO products VALUES (1, 19.9567);
SELECT id, ROUND(price, 2) AS display_price FROM products;
- यह उम्मीद करना कि
CEIL(-2.5)-3देगा, जबकि यह-2देता है क्योंकि यह positive infinity की ओर round करता है। ROUNDइस्तेमाल करना जहाँ आपको हमेशा ऊपर round करना हो, जैसे चाहिए boxes के लिए, जबCEILसही है।- negative numbers पर
FLOORइस्तेमाल करना और उम्मीद से छोटा number पाना, जैसेFLOOR(-2.5)-3है।
Chapter Quiz — Complete all 6 topics to unlock
0/6 topics done
Complete these topics first: