mysqlÖÐСÊýλÊýΪ1Ôõô´ò
ÔÚ mysql ÖУ¬½«Ð¡ÊýλÊýÉèÖÃΪ 1 µÄÒªÁìÓУº1. ʹÓà decimal Êý¾ÝÀàÐÍ£¬Ó﷨Ϊ decimal(precision, scale)£¬ÆäÖÐ scale Ö¸¶¨Ð¡ÊýλÊý¡£2. ʹÓà cast() º¯Êý£¬Ó﷨Ϊ cast(number as decimal(precision, scale))£¬½«Ð¡Êýת»»ÎªÖ¸¶¨Ð¡ÊýλÊýµÄÖµ¡£
ÔõÑùÔÚ MySQL Öн«Ð¡ÊýλÊýÉèÖÃΪ 1
ÔÚ MySQL ÖУ¬¿ÉÒÔͨ¹ýÒÔÏÂÁ½ÖÖÒªÁ콫СÊýλÊýÉèÖÃΪ 1£º
ÒªÁì 1£ºÊ¹Óà DECIMAL Êý¾ÝÀàÐÍ
DECIMAL Êý¾ÝÀàÐÍ¿ÉÒÔÖ¸¶¨Ð¡ÊýλÊý¡£Òª½«Ð¡ÊýλÊýÉèÖÃΪ 1£¬ÇëʹÓÃÒÔÏÂÓï·¨£º
DECIMAL(precision, scale)
µÇ¼ºó¸´ÖÆ
ÆäÖУº
precision Ö¸¶¨×ÜÊý×ÖλÊý£¨°üÀ¨Ð¡Êý룩
scale Ö¸¶¨Ð¡ÊýλÊý
Òª½«Ð¡ÊýλÊýÉèÖÃΪ 1£¬ÇëʹÓÃÒÔÏÂÓï·¨£º
DECIMAL(10, 1)
µÇ¼ºó¸´ÖÆ
Õ⽫½¨ÉèÒ»¸ö×ÜÊý×ÖλÊýΪ 10¡¢Ð¡ÊýλÊýΪ 1 µÄ DECIMAL Êý¾ÝÀàÐÍ¡£
ÒªÁì 2£ºÊ¹Óà CAST() º¯Êý
Ò²¿ÉÒÔʹÓà CAST() º¯Êý½«ÏÖÓеÄСÊýת»»ÎªÐ¡ÊýλÊýΪ 1 µÄÖµ¡£Óï·¨ÈçÏ£º
CAST(number AS DECIMAL(precision, scale))
µÇ¼ºó¸´ÖÆ
ÀýÈ磬Ҫ½«Êý×Ö 123.456 ת»»ÎªÐ¡ÊýλÊýΪ 1 µÄÖµ£¬ÇëʹÓÃÒÔÏÂÓï·¨£º
CAST(123.456 AS DECIMAL(10, 1))
µÇ¼ºó¸´ÖÆ
Õ⽫·µ»ØÒ»¸öֵΪ 123.5 µÄ DECIMAL Öµ¡£
ÒÔÉϾÍÊÇmysqlÖÐСÊýλÊýΪ1Ôõô´òµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡