Format number to 2 decimal places

When formatting number to 2 decimal places you have two options TRUNCATE and ROUND. You are looking for TRUNCATE function.

Examples:

Without rounding:

TRUNCATE(0.166, 2)
-- will be evaluated to 0.16

TRUNCATE(0.164, 2)
-- will be evaluated to 0.16

docs: http://www.w3resource.com/mysql/mathematical-functions/mysql-truncate-function.php

With rounding:

ROUND(0.166, 2)
-- will be evaluated to 0.17

ROUND(0.164, 2)
-- will be evaluated to 0.16

docs: http://www.w3resource.com/mysql/mathematical-functions/mysql-round-function.php


You want to use the TRUNCATE command.

https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_truncate


How about CAST(2229.999 AS DECIMAL(6,2)) to get a decimal with 2 decimal places


Just use format(number, qtyDecimals) sample: format(1000, 2) result 1000.00