Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

375
Views
Cómo formatear el número según la configuración regional del usuario en angular 2

Cómo formatear el número según la configuración regional del usuario en angular 2

Ejemplo: si la configuración regional del usuario es alemana (Alemania), el número se muestra como 1.234,56

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Ya hay una función disponible en JavaScript. Puedes simplemente llamarlo. https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString

Ejemplo :

 var number = 123456.789; // German uses comma as decimal separator and period for thousands console.log(number.toLocaleString('de-DE')); // → 123.456,789 // Arabic in most Arabic speaking countries uses Eastern Arabic digits console.log(number.toLocaleString('ar-EG')); // → ١٢٣٤٥٦٫٧٨٩ // India uses thousands/lakh/crore separators console.log(number.toLocaleString('en-IN')); // → 1,23,456.789 // the nu extension key requests a numbering system, eg Chinese decimal console.log(number.toLocaleString('zh-Hans-CN-u-nu-hanidec')); // → 一二三,四五六.七八九// when requesting a language that may not be supported, such as // Balinese, include a fallback language, in this case Indonesian console.log(number.toLocaleString(['ban', 'id'])); // → 123.456,789

Simplemente puede almacenar esta configuración regional en algún archivo constante y jugar con ella.

about 4 years ago · Santiago Trujillo Report

0

Puede crear un filtro que puede usar en toda su aplicación al mostrar números.

Creando un filtro:

 angular.module('myApp', []) .filter('formatNumber', function() { return function(input) { // Get the locale using any technique var locale = window.navigator.language; if (locale == 'GERMANY') { // test code, replace with your logic return // German formatted number else return // defaults }; })

Angular 2:

 import { Pipe, PipeTransform } from '@angular/core'; @Pipe({name: 'formatNumber'}) export class FormatNumberPipe implements PipeTransform { transform(value: string, args: string[]): any { if (!value) return value; // Get the locale using any technique var locale = window.navigator.language; if (locale == 'GERMANY') { // test code, replace with your logic return // German formatted number else return // defaults } }

Uso en HTML:

 <div> <span class="qty">{{ number | formatNumber }} </span> </div>
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!