user5312824
user5312824

Reputation:

Round up two decimals place to next multiple to ten - PHP

I have this question:
How can round two decimals place to next multiple to ten? Follow this example:

$number = 120.37
// I would like some functions or trick to transform this into 120.40

Is it possible in php?

Upvotes: 1

Views: 88

Answers (3)

aresklip
aresklip

Reputation: 86

try this

number_format(round($number,1), 2, '.', '');

or just

round($number,1);

if you not need it with 2 decimals

Upvotes: 1

Diego Ferri
Diego Ferri

Reputation: 2787

Try this

round($number * 10) / 10;

Upvotes: 0

Imtiaz Pabel
Imtiaz Pabel

Reputation: 5445

use this number format

number_format($number, 2, '.', '');

It will give output 120.40

Upvotes: 3

Related Questions