Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Working with decimal numbers in PHP

I want to somehow round the numbers for a rating system in PHP like this:

4.6667 = 4.6

5.0001 = 5.0

Is there any way to do that? (BTW, I read the data from a database.)

like image 405
The Worst Shady Avatar asked Dec 17 '22 00:12

The Worst Shady


1 Answers

You are not conforming to any single rule. For example:

4.6667 = 4.6
5.0001 = 5.1

See these functions anyway:

round
ceil
floor

And number_format.

like image 139
Sarfraz Avatar answered Dec 27 '22 16:12

Sarfraz