You must go float
so as not to lose the accuracy of the calculation and use number_format
to display ...
Notes:
It really depends on your needs and how you want your result to be processed if you just want to cut the mantissa after the second number or do some rounding.
Using BC math with a scale of 2, for example 2.10/1.10
, produce 1.90
using number_format(2.10/1.10, 2)
will result in 1.91
(rounding the results is exactly the same as SELECT CAST(2.10/1.10 as DECIMAL(10,2))
)
Update:. As indicated in the comments, there may be times when you lose accuracy. It is probably best to do calculations with arbitrary precision in MySQL itself, so you can be sure that nothing is freed up during mathematical operations.
source share