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

368
Views
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 answers
Answer question

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 Report

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 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!