# "php float calculation 2 decimal point" Answerâ€™s

Only authorized users can answer the question. Please sign in first, or register a free account.

Not the answer you're looking for? Browse other questions tagged :

Related Search Terms

Relevant Tags Search Terms

Try

`sprintf`

`("%.2f", $c);`

Floating point numbers are represented in IEEE notation based on the powers of 2, so terminating decimal numbers may not be a terminating binary number, that's why you get the trailing digits.

As suggested by Variable Length Coder, if you know the precision you want and it doesn't change (e.g. when you're dealing with money) it might be better to just use fixed point numbers i.e. express the numbers as cents rather than dollars

This way, you won't have any rounding errors if you do a lot of calculations before printing.