×ðÁú¿­Ê±¹ÙÍøµÇ¼

mysqlÖÐdecimalÓ÷¨

decimal Êý¾ÝÀàÐÍÔÚ mysql ÖÐÓÃÓÚ´æ´¢Àο¿¾«¶ÈµÄÊ®½øÖÆÊý×Ö£¬×èÖ¹¾«¶ÈËðʧ¡£ÆäÓ﷨Ϊ decimal(m, d)£¬ÆäÖÐ m Ϊ×î´óÊý×ÖλÊý£¬d ΪСÊýµãÓұߵÄÊý×ÖλÊý¡£Ìصã°üÀ¨×¼È·¶È¡¢Àο¿³¤¶È¡¢Êý¾ÝÍêÕûÐÔ¡£ÊÊÓÃÓÚÐèҪ׼ȷÅÌË㡢׼ȷÕÉÁ¿»òÇ¿ÖÆÖ´ÐÐÌض¨¾«¶ÈºÍ¹æÄ£µÄÊý¾Ý¡£Óë float ºÍ double Ïà±È£¬decimal µÄ¾«¶È¸ü¸ß£¬µ«ËÙÂʽÏÂý£¬³¤¶ÈÀο¿¡£

MySQL ÖÐ DECIMAL Êý¾ÝÀàÐ͵ÄÓ÷¨

DECIMAL Êý¾ÝÀàÐÍÓÃÓÚ´æ´¢Àο¿¾«¶ÈµÄÊ®½øÖÆÊý×Ö¡£Ëü²î±ðÓÚ FLOAT ºÍ DOUBLE ÀàÐÍ£¬ºóÕßʹÓø¡µãÔËË㣬¿ÉÄܻᵼÖ¾«¶ÈËðʧ¡£

Óï·¨

DECIMAL(M, D)

µÇ¼ºó¸´ÖÆ

M£º×î´óÊý×ÖλÊý£¨°üÀ¨Ð¡Êýµã×ó±ßµÄÊý×Ö£©

D£ºÐ¡ÊýµãÓұߵÄÊý×ÖλÊý

ÀýÈ磺

DECIMAL(10, 2)

µÇ¼ºó¸´ÖÆ

´ËÊý¾ÝÀàÐÍ¿ÉÒÔ´æ´¢×î´óֵΪ 99999999.99 µÄÊ®½øÖÆÊý×Ö£¬ÆäÖÐ 8 λÊý×ÖÔÚСÊýµã×ó±ß£¬2 λÊý×ÖÔÚÓұߡ£

Ìصã

׼ȷ£ºDECIMAL ÀàÐʹ洢׼ȷµÄÊ®½øÖÆÊý×Ö£¬×èÖ¹¾«¶ÈËðʧ¡£

Àο¿³¤¶È£ºÊý¾Ý³¤¶ÈÊÇÀο¿µÄ£¬ÓÉ M ºÍ D ¾öÒ飬½ÚÔ¼´æ´¢¿Õ¼ä¡£

Êý¾ÝÍêÕûÐÔ£ºDECIMAL ÀàÐÍÇ¿ÖÆÖ´ÐÐСÊýµãµÄλÖ㬱ÜÃâÊý¾ÝÊäÈë¹ýʧ¡£

ºÎʱʹÓÃ

ʹÓà DECIMAL Êý¾ÝÀàÐÍÊÊÓÃÓÚÒÔÏÂÇéÐΣº

ÐèҪ׼ȷÅÌËãµÄ²ÆÎñÊý¾Ý

ÐèÒª´æ´¢´øСÊýµÄ׼ȷÕÉÁ¿Öµ

ÐèҪǿÖÆÖ´ÐÐÌض¨¾«¶ÈºÍ¹æÄ£µÄÊý¾Ý

Óë FLOAT ºÍ DOUBLE µÄ½ÏÁ¿

ÌØÕ÷ DECIMAL FLOAT DOUBLE
¾«¶È ׼ȷ ½üËÆÖµ ½üËÆÖµ
³¤¶È Àο¿ ¿É±ä ¿É±ä
ËÙÂÊ ½ÏÂý ½Ï¿ì ½Ï¿ì

ʾÀý

ÒÔÏÂÊÇʹÓà DECIMAL Êý¾ÝÀàÐ͵ÄʾÀý£º

CREATE TABLE orders (
  order_id INT NOT NULL AUTO_INCREMENT,
  total_price DECIMAL(10, 2) NOT NULL
);

INSERT INTO orders (total_price) VALUES (123.45);

SELECT * FROM orders WHERE total_price > 100.00;

µÇ¼ºó¸´ÖÆ

ÒÔÉϾÍÊÇmysqlÖÐdecimalÓ÷¨µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
ÍøÕ¾µØͼ