I have a MySQL view called Balance
created from 2 tables order
and income
with PHPMyAdmin and contains some calculated fields ex: CustomerBalance
the decimal place become automatically 8, I mean the field Type is decimal(50,8)
How can i make it 2 only ?
FORMAT() function ##' which is rounded upto the number of decimal places specified (in the second argument) and returns the result as a string.
For a column named "Column" from a table named "Table", the following query will produce a the count of each row's decimal places: select length( substr( cast(Column as text), instr(cast(Column as text), '.
ROUND() Function in MySQL. The ROUND() function in MySQL is used to round a number to a specified number of decimal places. If no specified number of decimal places is provided for round off, it rounds off the number to the nearest integer.
You can use truncate
SELECT TRUNCATE(1.999,2);
return 1.99
select TRUNCATE(your_column,2) from your_table;
In the select
list where you calculate the CustomerBalance
expression, explicitly truncate or round (depending on your requirements) the result to 2 digits:
select ... round(..., 2) as CustomerBalance ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With