How to round a decimal value and display 0.50 instead of 0.5 in php

-2

I want to round a value in my php project in such a way that instead of showing me for example 12.5 it shows me the zero of 50 (12.50)

    
asked by Yily Miguel 20.12.2018 в 15:45
source

3 answers

0

In Twig (which, from what I see is the template system you are using), you also have a call to number_format that works in a very similar way:

{{ tu_numero | number_format(2, ',', '.') }}

The parameters are the following:

  • The first to indicate the number of decimals , in this example 2.
  • The second to indicate the character to use as decimal separator , in this example a comma.
  • The third value to indicate the character to be used as mile separator s in this case a period.
answered by 20.12.2018 / 16:00
source
0

you can do it like that
javascript:

var num=12.5;
num.toFixed(2);

php:

$num=12.5; 
money_format('%i', $number);
    
answered by 20.12.2018 в 16:00
0

In php you can use string number_format ( float $number , int $decimals = 0 , string $dec_point = ".")

    
answered by 20.12.2018 в 15:49