sqlÖÐroundµÄ×÷ÓÃ
round º¯ÊýÓÃÓÚ½«Êý×ÖËÄÉáÎåÈëµ½Ö¸¶¨µÄСÊýλÊý£¬Ó﷨Ϊ round(number, decimals)¡£Æä×÷ÓðüÀ¨ÃûÌû¯Êý×Ö¡¢Æ¾Ö¤¾«¶ÈÅÌËãºÍ½¨ÉèÖ¸¶¨Ð¡ÊýλÊýµÄÅÉÉúÁС£
SQL ÖÐ ROUND º¯ÊýµÄ×÷ÓÃ
ROUND º¯ÊýÓÃÓÚ½«Ö¸¶¨Ãü×ÖËÄÉáÎåÈëµ½Ö¸¶¨µÄСÊýλÊý¡£Ëü½ÓÊÜÁ½¸ö²ÎÊý£ºÒªËÄÉáÎåÈëµÄÊý×ÖºÍÄ¿µÄСÊýλÊý¡£
Óï·¨
ROUND(number, decimals)
µÇ¼ºó¸´ÖÆ
²ÎÊý
number£ºÒªËÄÉáÎåÈëµÄÊý×Ö»ò±í´ïʽ¡£
decimals£ºÒªËÄÉáÎåÈëµ½µÄÄ¿µÄСÊýλÊý¡£¿ÉÒÔÊÇÕýÕûÊý»ò¸ºÕûÊý¡£
ËÄÉáÎåÈë¹æÔò
ÈôÊÇСÊý²¿·ÖΪ 0.5 »ò¸ü´ó£¬ÔòÊý×Ö½«ÏòÉÏËÄÉáÎåÈë¡£
ÈôÊÇСÊý²¿·ÖСÓÚ 0.5£¬ÔòÊý×Ö½«ÏòÏÂËÄÉáÎåÈë¡£
ÈôÊÇÄ¿µÄСÊýλÊýΪ¸ºÊý£¬Ôòº¯Êý½«É¾³ý±ÈÖ¸¶¨Î»Êý¸ü¶àµÄÊý×Ö¡£
ʾÀý
ÏÂÃæÊÇһЩËÄÉáÎåÈëµÄʾÀý£º
ÊäÈë | decimals | Êä³ö |
---|---|---|
12.345 | 0 | 12 |
12.345 | 1 | 12.3 |
12.345 | 2 | 12.35 |
12.345 | -1 | 10 |
ÓÃ;
ROUND º¯ÊýÆÕ±éÓÃÓÚÒÔϳ¡¾°£º
ÃûÌû¯Êý×ÖÒÔ¾ÙÐÐÏÔʾ¡£
ƾָ֤¶¨¾«¶È¾ÙÐÐÅÌËã¡£
½¨Éè¾ßÓÐÌض¨Ð¡ÊýλÊýµÄÅÉÉúÁС£
×¢ÖØ
decimals ²ÎÊý¿ÉÒÔ°üÀ¨Ð¡Êý£¬ÔÊÐí¸ü׼ȷµÄËÄÉáÎåÈë¡£
ROUND º¯Êý²»»á¸Ä±äÊäÈëÊý×ÖµÄÏÖʵֵ£¬ËüÖ»»á·µ»ØËÄÉáÎåÈëºóµÄÖµ¡£
¹ØÓÚÐèÒª¸üÖØ´óµÄÉáÈë¹æÔòµÄÇéÐΣ¬Çë˼Á¿Ê¹ÓÃÆäËûº¯Êý£¬Èç CEILING »ò FLOOR¡£
ÒÔÉϾÍÊÇsqlÖÐroundµÄ×÷ÓõÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡