Tell .replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1,') , is there an analog of .replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1,') (jquery) in Angular? Purpose: to display the number in the form of 2 989 298.87 rubles.

  • + Is there an analog of .toFixed ()? - Vyacheslav Yashnikov
  • output to where? just show it or is it an input value and can it be edited right in it with preservation of formatting? - Grundy
  • I just output the result of calculations in a div, for example <div> {{a + b}} </ div> - Vyacheslav Yashnikov

1 answer 1

The number filter can help in part, it allows you to specify the number of characters in the fractional part, and also formats the number according to the en_US locale:

  1. the fractional part is separated by a point
  2. groups are separated by commas.

very simple to use:

 <div>{{(a+b) | number: 2}}</div> 

Print a number with two decimal places.

If you need to format it differently, you will have to write your own filter, or use one of the many modules.

The implementation of the number filter can be viewed in the source

  • And if you count and display in the controller, will the jquery functions work in the same place? - Vyacheslav Yashnikov
  • @ VyacheslavYashnikov, did not understand the question. The replace method has nothing to do with jQuery — it is a string method and can be called anywhere. - Grundy