NUMERIC और DECIMAL
numeric exact decimal numbers store करता है, जो इसे money के लिए सही choice बनाता है।
In this page:
Syntax
column_name numeric(precision, scale)
column_name numeric(10, 2)
NUMERIC/DECIMAL
numeric(precision, scale) exact digits रखता है: numeric(10,2) decimal point के बाद 2 के साथ 10 digits तक hold करता है। real और double precision binary floating-point types हैं जो 0.1 + 0.2 जैसी rounding errors दिखा सकते हैं।
numeric पर arithmetic exact है लेकिन slower। ROUND(x, n) n decimals तक round करता है।
Note:
Currency के लिए numeric और scientific data के लिए double precision इस्तेमाल करें।
उदाहरण: NUMERIC/DECIMAL
shop=# SELECT 0.1::double precision + 0.2::double precision AS float_sum, 0.1::numeric + 0.2::numeric AS numeric_sum;
float_sum | numeric_sum
-------------------+-------------
0.30000000000000004 | 0.3
shop=# SELECT ROUND(2.675, 2) AS rounded, 19.99::numeric(10,2) * 3 AS price_times_3;
rounded | price_times_3
---------+---------------
2.68 | 59.97
⚠️ Run this in your own terminal or Node.js environment.
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. #}
आम गलतियां
- money के लिए float इस्तेमाल करना
- precision और scale भूल जाना
- यह मान लेना कि numeric integer जितना fast है
चैप्टर सारांश
- numeric(p,s) exact है
- real और double precision approximate हैं
- money के लिए numeric इस्तेमाल करें
- ROUND decimals control करता है
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: