Skip to content

Instantly share code, notes, and snippets.

@infoshahin
Forked from nixon1333/banglaNumber.js
Created May 24, 2016 06:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save infoshahin/f177986437942b50e65bef34ed240eac to your computer and use it in GitHub Desktop.
Save infoshahin/f177986437942b50e65bef34ed240eac to your computer and use it in GitHub Desktop.
English number to Bangla number convertion
function toBangla (str)
{
//check if the `str` is not string
if(!isNaN(str)){
//if not string make it string forcefully
str = String(str);
}
//start try catch block
try {
//keep the bangla numbers to an array
var convert = ['০','১','২','৩','৪','৫','৬','৭','৮','৯'];
//now split the provided string into array by each character
var splitArray = str.split("");
//declare a empty string
var newString = "";
//run a loop upto the length of the string array
for (i = 0; i < splitArray.length; i++) {
//check if current array element if not number
if(isNaN(splitArray [i])){
//if not number then place it as it is
newString += splitArray [i];
}else{
//if number then get same numbered element from the bangla array
newString += convert[splitArray [i]];
}
}
//return the newly converted number
return newString;
}
catch(err) {
//if any error occured while convertion return the original string
return str;
}
//by default return original number/string
return str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment