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

285
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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