How to transform an integer into decimal?

1

I need a function to do the following, I get the number for example 15, and I need to turn it into a 1.0 decimal, rounding the 5 to 0.

I tried to use number_format(15, 1, '.', '') , but it returns me 15.0

How can I do this?

    
asked by anonymous 22.06.2015 / 16:03

1 answer

0

Something like this?

<?php

$a = 15;
$b = $a / 10; //1,5
$c = floor($b); //1  - arredonda para baixo

var_dump($a, $b, $c); //para você verificar a transformação do número

echo number_format($c, 1, '.', ''); //para exibir '1.0'

Other functions for rounding are round and ceil

    
22.06.2015 / 16:11