MySQL?ROUND?????????????????
???????????? ???????[ 2017/1/11 10:24:36 ] ????????????? MySQL
??????MySQL?У?ROUND???????????????????????????????????ROUND???????????????????????????????????????????????????????????????????????????
????????????
??????????????????????????test?????????????
????CREATE TABLE test (
????id int(11) NOT NULL AUTO_INCREMENT??
????field1 bigint(10) DEFAULT NULL??
????field2 decimal(10??0) DEFAULT NULL??
????field3 int(10) DEFAULT NULL??
????field4 float(15??4) DEFAULT NULL??
????field5 float(15??4) DEFAULT NULL??
????field6 float(15??4) DEFAULT NULL??
????PRIMARY KEY (id)
????) ENGINE=InnoDB DEFAULT CHARSET=utf8;
???????????????????test????????id????????????????Σ??????????????????????????????в??????????
????INSERT INTO test (field1?? field2?? field3?? field4?? field5?? field6) VALUE (100?? 100?? 100?? 1.005?? 3.5?? 2.5);
?????????????е?????????????
????mysql> select * from test;
????+----+--------+--------+--------+--------+--------+--------+
????| id | field1 | field2 | field3 | field4 | field5 | field6 |
????+----+--------+--------+--------+--------+--------+--------+
????| 1 | 100 | 100 | 100 | 1.0050 | 3.5000 | 2.5000 |
????+----+--------+--------+--------+--------+--------+--------+
????1 row in set (0.00 sec)
?????????????????????????SQL??????y???????????????
????SELECT
????round(field1 * field4)??
????round(field2 * field4)??
????round(field3 * field4)??
????round(field1 * 1.005)??
????round(field2 * 1.005)??
????round(field3 * 1.005)??
????round(field5)??
????round(field6)
????FROM test;
???????????????????????????101?????????????????????????100 * 1.005??????????????????????101???????????????????4??3???????????????????????????
????*************************** 1. row ***************************
????round(field1 * field4): 100
????round(field2 * field4): 100
????round(field3 * field4): 100
????round(field1 * 1.005): 101
????round(field2 * 1.005): 101
????round(field3 * 1.005): 101
????round(field5): 4
????round(field6): 2
????1 row in set (0.00 sec)
???????????????
?????????100*1.005?????????????е???????????????????????С????????????????
????????????????????????????????????????????????????????????????????????????????????mysql???????й???ROUND?????????????а???????????????
????· For exact-value numbers?? ROUND() uses the “round half up” rule???????????????ROUND???????????????
????· For approximate-value numbers?? the result depends on the C library. On many systems?? this means that ROUND() uses the “round to nearest even” rule: A value with any fractional part is rounded to the nearest even integer. ???????????????????????C??????????????ROUND?????????“????????”?????
??????????????????????????????????????????????????????????????????float???????????????????float?????????????????????????????????????????????????1.005??????С?????????????????????????????????????????????????????????field5??field6???ROUND????????????????????????????????????
???????
??????????????п??????????MySQL?????ROUND??????????????????????????????????а?????????????????????????????????
??????????????????????£?????????ο???? GITHUB ??? ??????????? ???????? Star????????follow????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11