← Back to MySQL Course | Chapter 13: Date & Numeric Functions | Lesson 1 of 6

ROUND CEIL FLOOR

ROUND, CEIL और FLOOR एक decimal को tidy करने के तीन तरीके हैं: सबसे नज़दीकी तक round करना, हमेशा ऊपर push करना, या हमेशा नीचे push करना।
Syntax
sql
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

sql
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

sql
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

sql
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

sql
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

sql
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;
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. यह उम्मीद करना कि CEIL(-2.5) -3 देगा, जबकि यह -2 देता है क्योंकि यह positive infinity की ओर round करता है।
  2. ROUND इस्तेमाल करना जहाँ आपको हमेशा ऊपर round करना हो, जैसे चाहिए boxes के लिए, जब CEIL सही है।
  3. negative numbers पर FLOOR इस्तेमाल करना और उम्मीद से छोटा number पाना, जैसे FLOOR(-2.5) -3 है।
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.