mysqlÖÐdecimalÔõôÓÃ
mysql ÖÐ decimal Êý¾ÝÀàÐÍÓÃÓÚÌåÏÖ׼ȷµÄСÊýºÍÇ®±ÒÖµ£¬Ìصã°üÀ¨£º×¼È·´æ´¢Ð¡Êý£¬²»Êܸ¡µãÊý¾ÝµÄÉáÈëÎó²îÓ°Ïì¡£¹æģȡ¾öÓÚ precision Öµ£¬ÀýÈç decimal(10, 2) µÄ¹æģΪ -9999999999.99 µ½ 9999999999.99¡£±È¸¡µãÊý¾ÝÀàÐ͸üÓÐÓÃÂÊ£¬ÓÉÓÚ´æ´¢µÄλÊý¸üÉÙ¡£
MySQL ÖÐ DECIMAL Êý¾ÝÀàÐ͵ÄʹÓÃ
DECIMAL Êý¾ÝÀàÐÍÓÃÓÚÌåÏÖ׼ȷµÄСÊýºÍÇ®±ÒÖµ£¬ËüÔÚ´ó´ó¶¼ÇéÐÎϱȸ¡µãÊý¾ÝÀàÐ͸üÊʺϡ£
Óï·¨
DECIMAL(precision, scale)
µÇ¼ºó¸´ÖÆ
precision£ºÖ¸¶¨Ãü×ÖµÄ×ÜλÊý£¬°üÀ¨Ð¡ÊýµãºóµÄλÊý¡£
scale£ºÖ¸¶¨Ð¡ÊýµãºóµÄλÊý¡£
ʾÀý
CREATE TABLE sales ( price DECIMAL(10, 2) );
µÇ¼ºó¸´ÖÆ
Õ⽫½¨ÉèÒ»¸öÃûΪ sales µÄ±í£¬ÆäÖÐ price ×Ö¶ÎÊÇÒ»¸ö DECIMAL Êý¾ÝÀàÐÍ£¬×ÜλÊýΪ 10£¬Ð¡ÊýµãºóÓÐ 2 λ¡£
Ìصã
׼ȷÐÔ£ºDECIMAL Êý¾ÝÀàÐÍ¿ÉÒÔ׼ȷ´æ´¢Ð¡Êý£¬²»Êܸ¡µãÊý¾ÝµÄÉáÈëÎó²îÓ°Ïì¡£
¹æÄ££ºDECIMAL Êý¾ÝÀàÐ͵Ĺæģȡ¾öÓÚ precision Öµ¡£ÀýÈ磬DECIMAL(10, 2) µÄ¹æģΪ -9999999999.99 µ½ 9999999999.99¡£
´æ´¢Ð§ÂÊ£ºDECIMAL Êý¾ÝÀàÐͱȸ¡µãÊý¾ÝÀàÐ͸üÓÐÓÃÂÊ£¬ÓÉÓÚ´æ´¢µÄλÊý¸üÉÙ¡£
×î¼Ñʵ¼ù
ʹÓà DECIMAL Êý¾ÝÀàÐÍʱ£¬Çë˼Á¿ÒÔÏÂ×î¼Ñʵ¼ù£º
½öÔÚÐèҪ׼ȷÅÌËãʱʹÓà DECIMAL¡£
Ñ¡ÔñºÏÊ浀 precision ºÍ scale£¬×èÖ¹²»ÐëÒªµÄ´æ´¢¿Õ¼äÆÌÕÅ¡£
¹ØÓÚÇ®±ÒÖµ£¬Ê¹ÓÃÕûÊý»ò¾ßÓÐÈ·¶¨Ð¡ÊýµãλÖÃµÄ DECIMAL£¬ÀýÈç DECIMAL(10, 2)¡£
×èÖ¹½« DECIMAL ÖµÓ븡µãÖµ»ìÏýʹÓã¬ÓÉÓÚÕâ¿ÉÄܻᵼÖÂÉáÈëÎó²î¡£
ÒÔÉϾÍÊÇmysqlÖÐdecimalÔõôÓõÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡