0

In the input I have a number:1000000 or 1000

I want to format it to: 1 000 000 or 1 000 respectively.

I tried to use a Pipe but it did not work out, what could be the problem?

{{  value | number : '1.1-10'}}
Valitskiy Dmitriy
  • 150
  • 1
  • 1
  • 9

3 Answers3

3

You can use the number pipe like this,

   <h1>{{value | number:'.2'}}</h1>

DEMO

Sajeetharan
  • 203,447
  • 57
  • 330
  • 376
0

To reproduce in this format, do the following:

HTML

{{  value | number : '1.0-0'}}  /* 0 decimal digits */

{{  value | number : '1.1-10'}} /*1.1-10 means: at least one digit before decimal point, at least 1 digit after decimal point but no more than 10 digits.*/

app.module.ts

import { LOCALE_ID } from '@angular/core';

...
   @NgModule({
....    
providers: [{ provide: LOCALE_ID, useValue: 'fr-FR' },....
// or your country local. For the thousands delimitation as space 'fr' works

Output

1 000 000

Vega
  • 25,886
  • 26
  • 85
  • 95
-1
public splitNumber(humidity: number):string {
    if(humidity == 0){
      return 0+"";
    }
    var str = humidity.toString();
    var numarray = str.split('.');
    var a = new Array();
    a = numarray;
    return a[0] +"."+this.numberFist(parseInt(a[1],10));
  }
Tienanhvn
  • 141
  • 5
  • 9
  • 1
    This just looks like a cut and paste that doesn't match the question, it doesn't do the second space for 1 000 000 for example. – Steve Aug 23 '19 at 01:48