# How work in php with money?

I have price:
169.00 EUR
1 EUR = 3.8804 PLN
So I show on page: 655.79 PLN using that script:

``````
\$x = 3.8804;
\$eur = 169;
\$pln = \$eur * \$x;
echo round(\$pln, 2);

``````

So for 3 the same products customer should pay 1967.37 PLN (655.79 * 3)
But when I write:

``````
\$x = 3.8804;
\$eur = 169;
\$pln = \$eur * \$x * 3;
echo round(\$pln, 2);

``````

I get 1967.36 PLN What is the rule - how work in php with prices - money ?

its all about rounding, and when it is applied.
169.00 * 3.8804 = 655.7876
655.7879 rounded to 2 decimals = 655.79
655.79 * 3 = 1967.37
Here the rounding was applied in between calculations and thus the result is 1967.37

169 * 3 * 3.8804 = 1967.3628
because no rounding have been applied yet, and when you round the result to 2 decimals, it will end up at 1967.36

so each time when I multiply price by number (which isnâ€™t integer) I must use round() - yes ?

lolâ€¦little offtropicâ€¦
if it is for really big supermarket chain
the timing of rounding can make huge different here
3.46 dollar product
you round it
3.5*100
where as if you do
round (346.78) after multipying by 100
then it would be 347 only
3\$ per customerâ€¦so be very careful with itâ€¦

No, you do all the adding and multiplying, and then ypou round the result.

But after each SINGLE operation, so:
not:
round(169 * 3.8804 * 27.4, 2) = 17968.58 - wrong

but:
round(169 * 3.8804, 2) = 655.79
round(655.79 * 27.4, 2) = 17968.65 - good

yes ?

What price is the customer presented with?

If you show the price as 169 EUR, and the customer pay in PLN, you need to do the rounding after all factors are multiplied (EUR * convert_factor * Quantity), to get the correct PLN at checkout.

If you show the price as 655.79 PLN, then you already have done the currency calculation, and the rounding associated with it.
All you need is to multiply price and amount to get the correct PLN at checkout

case: customer wants to buy 27.4 items of some product/service.

you list the price as 169 EUR
customer will pay in PLN
the value should be 1693.880427.4 = 17968.58

27.4 items
each costs 169.00 EUR
169.00*27.4 = 4630.60 EUR

4630.60 * 3.8804 = 17968.58 PLN

Alternative:
If you list the product/service price to be 655.79 PLN
then the customer simply pays 655.79*27.4 = 17968.65

27.4 items
each cost 655.79 PLN
27.4*655.79 = 17968.65 PLN

ok now I understand (in my case I use your second situation which you described) - thx You very much