I have a little problem with round() in php. I don't know, if I really make it correct. (it is an order system)

$amount can be decimal 14,8 $price can be decimal 10,5 (in the database)

I am using the following rounding at this moment The $price is for one $amount

function round_amount($amount) { return (float) round($amount, 8); } function round_price($amount) { return (float) round($amount, 5); } //if some one have more decimal chars like 10.000000009 round_amount(10.000000009); //will be 10.00000001 //if some one have more decimal chars like 10.000009 round_price(10.000009); //will be 10.00001 //also this is possible round_price(round_amount(10.000000009)*round_price(10.000009))

Is this way correct to use round? Some user are using more than 16 decimals. I am deducting / adding the results in the user database.

But I see, that some user have about 5-10 cents too much!

Is the only way to resolve this, to allow ONLY 8 and 5 decimals? And warn the user, if he tries to use more? But than I will get an problem with the round_cur(round_amount(10.000000009)*round_cur(10.000009))

I hope some one understand what I am meaning, or can tell me, if my way to round is correct.

Update 1

$amount = 10.12398413498579889173459873; $price = 5.1938457198347695; echo round_cur(round_amount($amount)*round_cur($price))."<br />"; echo round_cur($amount*$price); //returns //52.58245 //52.58241

Interesting!