DayTripperID DayTripperID - 22 days ago 17
MySQL Question

MySQL DECIMAL(3,2) trailing zeros not showing

enter image description hereHow can I get trailing zeros for type DECIMAL(3,2) to show?

For example, if I insert value 1.50, queries show it as 1.5 instead. See screenshot below. The schema is on the left, the query is on the right, and the results are displayed at the bottome. Thanks!

Answer

Assuming you are asking about what you observe in MySQL directly, it should first be noted that even though the trailing zeros may be missing in the query output, the precision internally should not be affected.

If you want to retain the full width of the DECIMAL, you can try either of the following:

SELECT CAST(UNIT_PRICE AS CHAR)

or

SELECT CONCAT(UNIT_PRICE)
Comments