Home >Database >Mysql Tutorial >How to Format Numbers to Two Decimal Places Without Rounding in MySQL?
In order to display a number with two decimal places without rounding the original number, it is possible to use the TRUNCATE function. This function removes all decimal places beyond the specified number.
To truncate a number to two decimal places, the following syntax can be used:
TRUNCATE(number, 2)
For instance, to truncate the number 2229.999 to two decimal places, the following expression can be used:
TRUNCATE(2229.999, 2)
The result of this expression will be 2229.99.
In addition to TRUNCATE, the ROUND function can also be used to format numbers to a specified number of decimal places. However, ROUND rounds the number to the nearest decimal place, which may not be desirable in some cases.
For more information on the TRUNCATE function, refer to the MySQL documentation: https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_truncate
For more information on the ROUND function, refer to the MySQL documentation: https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_round
The above is the detailed content of How to Format Numbers to Two Decimal Places Without Rounding in MySQL?. For more information, please follow other related articles on the PHP Chinese website!