??????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????