1, round (X,D): For data rounding, round (x), in fact, is round (x,0), also is the default d is 0;
One of the notable points here is that D can be a negative number, when the D-bit integer bit to the left of the specified decimal point is 0, and the decimal places are 0;
SELECT ROUND (100.3465,2), ROUND (100,2), ROUND (0.6,2), ROUND (114.6,-1);
Results were: 100.35,100,0.6,110
2. TRUNCATE (x,d): The function returns the number x that is removed to the D-digit after the decimal point. If the value of D is 0, the result does not have a decimal point or a fractional part. If D is set to a negative number, then the value of all lows after the beginning of the first digit of the decimal point (zero) x is truncated.
SELECT TRUNCATE (100.3465,2), TRUNCATE (100,2), TRUNCATE (0.6,2), TRUNCATE (114.6,-1);
Results were: 100.34,100,0.6,110
3. FORMAT (x,d): Force the D Decimal, the integer part exceeds three bits, and the returned result is a string type
SELECT format (100.3465,2), Format (100,2), format (, 100.6,2);
Results were: 100.35,100.00,100.60
4. CONVERT (value,type); type conversion, equivalent to interception
Type
- Binary, with binary prefix effect: binary
- Character type, with parameters: CHAR ()
- Date: Date
- Time:
- DateTime Date/Time type
- Floating point number: DECIMAL
- Integer: Signed
- unsigned integer: UNSIGNED
SELECT Convert (100.3465,decimal (10,2)), CONVERT (100,decimal (10,2)), CONVERT (100.4,decimal (10,2));
Results were: 100.35,100,100.4
MySQL retains two decimal places