MySQL View Decimal Place

I have a MySQL view called Balance created from 2 order and income tables using PHPMyAdmin and containing some calculated ex fields: CustomerBalance decimal place automatically becomes 8, I mean the Decimal type field decimal(50,8)
How can I do only 2?

+5
source share
2 answers

You can use truncate

  SELECT TRUNCATE(1.999,2); 

return 1.99

  select TRUNCATE(your_column,2) from your_table; 
+2
source

In the select list, where you evaluate the CustomerBalance expression, explicitly truncate or round (depending on your requirements) the result to two digits:

 select ... round(..., 2) as CustomerBalance ... 
+1
source

Source: https://habr.com/ru/post/1258029/


All Articles