How to format monetary value in Laravel

Asked

Viewed 7,283 times

3

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)

  • 1

    Could you post the snippet of code where you need help? It would help the community understand your problem.

  • Simples @Felipepaetzold ... {{ $lst->vl_valor_tot_contrato }} is displayed in monetary format Ex. R$ 105.273,54

  • In your case I think it would be better if you create a js mask or use the jquery Money library (https://plugins.jquery.com/maskMoney/) .

1 answer

6


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

For example:

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

Also remember to set the locale correctly in PHP.

setlocale(LC_MONETARY, 'pt_BR');

If the function money_format 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, ',', '.') }}  

Sources:

  1. Soen - Using number_format method in Laravel
  2. Sopt - Number formatting (php)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.