Borsn - 6 months ago 24

PHP Question

After converting currencies, I get a float that would look something like

`2.68`

Tried rounding up with

`ceil($input / 10) * 10`

I'd like to get

`2.70`

The more complicated way for me to do this would be to

`explode`

`.`

`68`

`ceil`

But what If the number is

`2.96`

`3.00`

Answer

You simply got the math wrong, it should be multipled-then-divided, not the other way around:

```
ceil($input * 10) / 10
```

But that only rounds up. Rounding in each direction works with `round`

...

```
round($input * 10) / 10
```

But wait, `round`

has a second param, just for this! :)

```
round($input, 1) // round with precision of 1 digits after the decimal point
```