Last active
December 17, 2024 10:55
-
-
Save miladd3/f7b41598897c2147db16d9770ae1f281 to your computer and use it in GitHub Desktop.
latin to Persian number pure JS function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Converts a Latin number to its Persian numeral representation. | |
* | |
* @param {string|number} v - The input number or string to convert. | |
* @returns {string} - The Persian numeral representation of the input. | |
*/ | |
function toPersianNumber(v) { | |
const PersianNumber = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹']; | |
const vString = v.toString(); | |
const chars = vString.split('').map(char => /\d/.test(char) ? PersianNumber[char] : char); | |
return chars.join(''); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment