my script calculates a number X by dividing two other numbers, A by B.
X=A/B
when i use number_format(A,2) on A before calculating X, i get a very odd number. Actual figures:
1,045.00 / 5 = 0.2
but if i don’t use number_format on A before the division, i get the correct answer. Is number_format somehow making A into a non-number?
1045 / 5 = 209
number_formatshould be used only while pretty printing the number. Its return value should not used in calculation as you did.Example:
If
$A = 1045;then
number_format($A,2)will be1,045.00now if you treat1,045.00as a number it will be1as comma and remaining char will be ignored and1/2is0.5which you are getting.