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

281
Views
How can i Convert persian digits to english digits?

I just want to change the shape of the numbers from Persian to English(i mean like this 1400/06/31). I mean to keep it Persian. Only the text font should be English. How can I do this?

 var today = new Date().toLocaleDateString('fa-IR');
  var field = document.querySelector('#tday');
  field.value = today;
<input type="text" name="tday" class="form-control w-100 text-center d-inline-block" id="tday">

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You can use this function to convert Persian numbers to English numbers

export default function toEnglishDigits(num) {

  const id = {
    '۰': '0',
    '۱': '1',
    '۲': '2',
    '۳': '3',
    '۴': '4',
    '۵': '5',
    '۶': '6',
    '۷': '7',
    '۸': '8',
    '۹': '9',
  }
  return num ? num.toString().replace(/[^0-9.]/g, function (w) {
    return id[w] || w
  }) : null
}

and use this to convert English numbers to Persian numbers

export default function toPersianDigits (num) {
  if (num?.toString()) {
    const persianNumbers =
      '\u06F0\u06F1\u06F2\u06F3\u06F4\u06F5\u06F6\u06F7\u06F8\u06F9'
    return new String(num).replace(/[0123456789]/g, (d) => {
      return persianNumbers[d]
    })
  }
  return num
}

you can also pass strings to these functions with any format.

about 4 years ago · Juan Pablo Isaza Report

0

If you are okay with adding a package, use Persian Tools digitsFaToEn function:

var englishNumber = digitsFaToEn("۱۴۰۰/۰۶/۳۱")  // englishNumber = 1400/06/31

https://github.com/persian-tools/persian-tools

about 4 years ago · Juan Pablo Isaza Report

0

To convert English (Arabic) numbers to Persian (Farsi) numbers, the following one-liner code will do the job.

It will change all Farsi numbers but keep everything else unchanged including the position of all other text.

const toFa = n => n.replace(/\d/g, d => "۰۱۲۳۴۵۶۷۸۹"[d])

// Tests
console.log(toFa("1400/06/31"));             // "۱۴۰۰/۰۶/۳۱"
console.log(toFa("The number is 25,000"));   // "The number is ۲۵,۰۰۰"
console.log(toFa("عدد 1234.78 است"));         // "عدد ۱۲۳۴.۷۸ است"
console.log(toFa("من متولد 1975/10/25 هستم"));  //"من متولد ۲۳/۱۰/۱۹۷۵ هستم"

about 4 years ago · Juan Pablo Isaza 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!