Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

257
Visualizações
How to replaceAll the numbers to Arabic or Persian

I'm using const to define changes and took me so long. How can I use them and how can I brief the codes?:

const [num0en, num1en, num2en, num3en, num4en, num5en, num6en, num7en, num8en, num9en, percEn] = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "%"]
const [num0fa, num1fa, num2fa, num3fa, num4fa, num5fa, num6fa, num7fa, num8fa, num9fa, PercFa] = ["۰", "۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹", "٪"]
const En0 = "0";
const Pe0 = "۰";
const En1 = '1';
const Pe1 = '۱';
const En2 = "2";
const Pe2 = "۲";
const En3 = "3";
const Pe3 = "۳";
const En4 = "4";
const Pe4 = "۴";
const En5 = "5";
const Pe5 = "۵";
const En6 = "6";
const Pe6 = "۶";
const En7 = "7";
const Pe7 = "۷";
const En8 = "8";
const Pe8 = "۸";
const En9 = "9";
const Pe9 = "۹";
const EnPercents = "%";
const PePercents = "٪";
const Rep0 = num0en.replaceAll(En0, Pe0);
const Rep1 = num1en.replaceAll(En1, Pe1);
const Rep2 = num2en.replaceAll(En2, Pe2);
const Rep3 = num3en.replaceAll(En3, Pe3);
const Rep4 = num4en.replaceAll(En4, Pe4);
const Rep5 = num5en.replaceAll(En5, Pe5);
const Rep6 = num6en.replaceAll(En6, Pe6);
const Rep7 = num7en.replaceAll(En7, Pe7);
const Rep8 = num8en.replaceAll(En8, Pe8);
const Rep9 = num9en.replaceAll(En9, Pe9);
const RepPer = percEn.replaceAll(EnPercents, PePercents);
const ReplaceAllNumbers = Rep0&&Rep1&&Rep2&&Rep3&&Rep4&&Rep5&&Rep6&&Rep7&&Rep8&&Rep9&&RepPer
    var post =  "0123456789";
// I need to use it in post below:
document.write(post);

and by the way, you would notice some mistakes. I beg you pardon beforehand..

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Use a regular expression, and use a function as the replacement so it can return the corresponding replacement. This correspondence can be in an object.

const enToPe = {
    [num0en]: num0fa,
    [num1en]: num1fa,
    ..
};

let result = post.replace(/./g, char => enToPe[char] || char);
console.log(result);
about 4 years ago · Juan Pablo Isaza Relatório

0

var persianIran = "fa-IR"
var arabicEgypt = "ar-EG"

let num = 1234567890;

document.getElementById("num").innerText = num.toLocaleString(persianIran, {
  style: "decimal",
  useGrouping: false
});

document.getElementById("num1").innerText = num.toLocaleString(arabicEgypt, {
  style: "decimal",
  useGrouping: false
});

num = .42;
document.getElementById("pct").innerText = num.toLocaleString(persianIran, {
  style: "percent",
  useGrouping: true
});

document.getElementById("pct1").innerText = num.toLocaleString(arabicEgypt, {
  style: "percent",
  useGrouping: true
});

num = 1027;
document.getElementById("cur").innerText = num.toLocaleString(persianIran, {
  style: "currency",
  currency: "EUR"
});
document.getElementById("cur1").innerText = num.toLocaleString(arabicEgypt, {
  style: "currency",
  currency: "EUR"
});
div {
  display: inline-block;
  margin: 0 20px
}

div>p:first-child {
  margin-bottom: 8px;
  border-bottom: 1px solid gray;
  font-weight: bold;
}

p {
  margin: 2px;
}
<div>
  <p>Values</p>
  <p>1234567890 as Decimal</p>
  <p>.42 as Percent</p>
  <p>1027 as Currency</p>
</div>
<div>
  <p>Persian-Iran</p>
  <p id="num"></p>
  <p id="pct"></p>
  <p id="cur"></p>
</div>
<div>
  <p>Arabic-Egypt</p>
  <p id="num1"></p>
  <p id="pct1"></p>
  <p id="cur1"></p>
</div>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda