I'm building a software that takes integers from users and does some calculations and then outputs the result. The thing is that I want to take users numbers using English numbers(0, 1, 2, etc.)
and I want to present the numbers using Persian numbers(like Arabic) in the output. I've read some topics on Unicode conversion and things like replace()
and charCodeAt()
but I can't understand the code.
Here's a piece of code.(It converts Persian numbers into English numbers but I want to do the opposite.)
var yas ="٠١٢٣٤٥٦٧٨٩";
yas = Number(yas.replace(/[٠١٢٣٤٥٦٧٨٩]/g, function (d) {
return d.charCodeAt(0) - 1632;
}).replace(/[۰۱۲۳۴۵۶۷۸۹]/g, function (d) { return d.charCodeAt(0) - 1776; })
);