Last active
October 20, 2024 05:41
-
-
Save sharif2008/275d7e03b149f2a42ed2878cf57edf35 to your computer and use it in GitHub Desktop.
Converting English number to Bangla in Javascript
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
var finalEnlishToBanglaNumber={'0':'০','1':'১','2':'২','3':'৩','4':'৪','5':'৫','6':'৬','7':'৭','8':'৮','9':'৯'}; | |
String.prototype.getDigitBanglaFromEnglish = function() { | |
var retStr = this; | |
for (var x in finalEnlishToBanglaNumber) { | |
retStr = retStr.replace(new RegExp(x, 'g'), finalEnlishToBanglaNumber[x]); | |
} | |
return retStr; | |
}; | |
var english_number="123456"; | |
var bangla_converted_number=english_number.getDigitBanglaFromEnglish(); | |
//outputs : ১২৩৪৫৬ | |
console.log(bangla_converted_number); //or alert(bangla_converted_number); |
Thanks
welcome @naazim7 and @mayeenulislam
export const getBanglaDigit = (digit: number) => {
const banglaDigit = ['০', '১', '২', '৩', '৪', '৫', '৬', '৭', '৮', '৯']
return digit.toString().replace(/\d/g, (d) => banglaDigit[+d])
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As of line#11, the input number has to be
string
...Usage for numeral values would be:
BTW, thank you for the gist. <3