FORMAT Function
In this page:
FORMAT(number, decimal_places[, locale])
Basic Number Formatting
FORMAT किसी number को decimal places की एक चुनी गई संख्या तक round करता है और readability के लिए comma separators insert करता है, 1234567.891 जैसी किसी चीज़ को display purposes के लिए '1,234,567.89' में बदलते हुए।
उदाहरण: Basic Number Formatting
SELECT FORMAT(1234567.891, 2) AS formatted;
Locale-Specific Formatting
एक optional तीसरा argument आपको एक locale specify करने देता है, यह बदलते हुए कि thousands separator और decimal point के लिए कौन से characters इस्तेमाल हों regional conventions से match करने के लिए — कुछ locales एक period इस्तेमाल करती हैं जहाँ दूसरी एक comma, और उल्टा।
उदाहरण: Locale-Specific Formatting
SELECT FORMAT(1234567.891, 2, 'de_DE') AS german_format;
बड़े Numbers Format करना
Formatted output reports और dashboards में real difference लाता है, क्योंकि बड़े statistics या totals को एक नज़र में scan करना कहीं आसान है एक बार वे readable groups of three digits में break हो जाएँ।
उदाहरण: Formatting Large Numbers
CREATE TABLE stats (id INT, total_users INT);
INSERT INTO stats VALUES (1, 1234567);
SELECT FORMAT(total_users, 0) AS readable_total FROM stats;
Zero Decimals के साथ Formatting
decimal-place argument को 0 set करना आपको बिल्कुल कोई fractional part न वाला comma-grouped output देता है, जो total orders या user sign-ups जैसी whole-number counts के लिए handy है जहाँ decimals meaningless होते।
उदाहरण: Formatting with Zero Decimals
SELECT FORMAT(48210, 0) AS signups;
FORMAT बनाम ROUND
FORMAT हमेशा एक text string return करता है, जबकि ROUND एक plain number return करता है जिसके साथ आप अभी भी math कर सकते हैं। FORMAT सिर्फ उस point पर इस्तेमाल करें जहाँ आप एक user को एक value दिखा रहे हों, और calculations को unformatted number पर चलाते रहें।
उदाहरण: FORMAT vs ROUND
SELECT FORMAT(1234.5678, 2) AS display_value, ROUND(1234.5678, 2) AS math_value;
FORMATका result store करना और उस पर math करना, क्योंकि यह commas वाली एक string return करता है।- यह भूल जाना कि
FORMATnumber को दिए गए decimals तक round करता है। - बिना तीसरे argument के हर locale में same grouping characters की उम्मीद करना।
CONCATऔरCONCAT_WSstrings जोड़ते हैं, औरLENGTHतथाCHAR_LENGTHउन्हें measure करते हैं।UPPER,LOWER, औरTRIMfunctions case बदलते हैं और extra spaces हटाते हैं।SUBSTRING,REPLACE, औरFORMATtext extract, substitute, और format करते हैं।
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: