Today little ape circle to share with you is the use of MySQL in 4 ways to preserve decimals, I hope to help you, let you work more convenient. 1 round(x,d) round(x,d) round(x,0)
Now, one thing to notice here is that d can be negative, so you specify that the d bits to the left of the decimal point are 0, and the decimal places are 0; 1 SELECT ROUND (100.3465, 2), ROUND (100, 2), ROUND (0.6, 2), ROUND (114.6, 1); 2 TRUNCATE(x,d) returns the truncated number x to the d decimal place. If the value of d is 0, the result has no decimal point or fractional part. If d is set to negative, truncate (zero) all lower values from the d to the left of the x decimal point. 1 the SELECT TRUNCATE (100.3465, 2), TRUNCATE (100, 2), TRUNCATE (0.6, 2), TRUNCATE (114.6, 1); The results are as follows: 100.34, 100,0.6,110 3 FORMAT (x,d) FORMAT (x,d) FORMAT (x,d) FORMAT (x,d) SELECT FORMAT(100.3465,2),FORMAT(100,2),FORMAT(,100.6,2); Results: 100.35,100.00, 100.60
4 Convert (num, type) Type conversion, equivalent to interception
Type: binary CHAR() DATE: DATETIME: TIME DATETIME type: DATETIME Floating point number: DECIMAL Integer: SIGNED unsigned integer: UNSIGNED 1 SELECT the CONVERT (100.3465, a DECIMAL (10, 2)), the CONVERT (100, DECIMAL (10, 2)), the CONVERT (100.4, a DECIMAL (10, 2)); The result is 100.35, 100,100.4, 100.35, 100,100.4, 100.35, 100,100.4, 100.35, 100,100.4, 100.35, 100,100.4