How to format monetary value in Laravel

1

I would like to know how to format monetary values in Laravel. Is there a package or method that is for the framework ?

{{ $lst->vl_valor_tot_c‌​ontrato }} is displayed with monetary formatting like this: (R$ 105.273,54)

    
asked by anonymous 16.08.2016 / 19:39

1 answer

2

To do this on the server side with PHP use the money_format function.

For example:

{{ money_format('%n', $lst->vl_valor_tot_c‌​ontrato ) }}

Do not forget to set the locale correctly in PHP.

setlocale(LC_MONETARY, 'pt_BR');

If the money_format function is not available in your installation, you can also get the result with the function number_format

{{  'R$ '.number_format($lst->vl_valor_tot_c‌​ontrato, 2, ',', '.') }}  

Fonts :

  • SOEn - Using number_format method in Laravel
  • SOpt - Numbering (php)
  • 21.08.2016 / 18:36