- 1. Call the MySQL formatted decimal function format (x,d)
For example:
[HTML]View PlainCopy
- Select Format (23456.789,2);
[HTML]View PlainCopy
- Select Formate (salary,2);
Output:
[HTML]View PlainCopy
- 23,456.79
, the format () function rounds the fractional part, and the integer part formats the output from right-to-left with a comma for every 3 bits, such as:2. Call MySQL's own function truncate (X,D)For example:
[HTML]View PlainCopy
- Select truncate (23456.789,2);
[HTML]View PlainCopy
- Select truncate (salary,2);
Output:
[HTML]View PlainCopy
- 23456.78
The truncate () function will take the decimal portion of the 2-bit value directly out of the way, such as:3. Call MySQL's own function convert (expr,type);
For example:
[HTML]View PlainCopy
- Select CONVERT (23456.789,decimal (10,2));
[HTML]View PlainCopy
- Select CONVERT (Salary,decimal (10,2));
Output:
[HTML]View PlainCopy
- 23456.79
The CONVERT () function rounds the fractional part, explaining the decimal (10,2), which represents the resulting integer portion of the result, plus fractional bits of less than or equal to 10, and fractional bits of 2, such as:In general, we will choose the Third Way
MySQL Query results after unit conversion number of decimal place retention method