Format monetary value with Angularjs

Asked

Viewed 1,327 times

0

I’m getting the following values

<h3 id="valor">Valor Mensalidade: R${{curso_se.preco_curso}}</h3>       
<h1 style="color:green;">PrimeiraMensalidade:R${{curso_se.preco_matricula}}</h1>

But they are coming with point and without separation of houses from the thousand, for example: 2.432,00

I had tried to give a replace but it didn’t work

$("#valor").val(replace(".", ","));
  • take a look at this so-called lib numbro is to form number, currency, percentage, and see if it helps you

  • tries: {curso_se.path_name.replace('.', ',')}}

1 answer

4


Please don’t do this kind of stunt. Do it the right way.

Add the script angular-locale for the location you intend to use (I used en in the example) and then make use of the filter currency.

angular.module('app', []).controller('mainCtrl', function($scope) {
  $scope.preco_matricula = 1150.50 ;
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-i18n/1.6.7/angular-locale_pt-br.js"></script>

<div ng-app="app" ng-controller="mainCtrl">
  <h1>PrimeiraMensalidade: {{ preco_matricula | currency }}</h1>
</div>

  • hello thanks worked and sorry, I thought this way was the right one gave me this tip I thought would work. ah obg by Edit in Portuguese too, I wrote running.

  • Quiet, good to help.

  • 1

    Thank you very much! I spent a whole day trying to do the aforementioned gambiarra, and when I decided to search correctly brought me here! Thanks!

Browser other questions tagged

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