Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

370
Vistas
Full-width Numbers convert to half-width Numbers in jQuery / JS

A would like to convert Full-width Numbers (e.g. 123) to half-width Numbers (e.g. 123). I found code do this in PHP but not in JS. Could anyone helps? Thanks.

function fullWidthNumConvert(fullWidthNum){
    // Magic here....
    ....
    return halfWidthNum;
}
about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Do a string .replace(), using a regular expression to match the characters in question. The callback in .replace()'s second argument can get the character code of the matched character and subtract from that to get the character code of the standard digit, then convert that back to a string.

function fullWidthNumConvert(fullWidthNum){
    return fullWidthNum.replace(/[\uFF10-\uFF19]/g, function(m) {
      return String.fromCharCode(m.charCodeAt(0) - 0xfee0);
    });
}


console.log(fullWidthNumConvert("0123456789"));
console.log(fullWidthNumConvert("Or in the middle of other text: 123. Thank you."));

about 4 years ago · Santiago Trujillo Denunciar

0

Using String Normalize MDN with "NFKC" as the Unicode Normalization Form

const str = "150721";
console.log(str.normalize('NFKC')); // 150721

https://www.unicode.org/charts/normalization/chart_Number-Decimal.html

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda