Created
February 17, 2020 02:17
-
-
Save Dharisd/97d4fcd9727633d267eb5a35964ebe26 to your computer and use it in GitHub Desktop.
This file contains 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
ones = [ | |
"", | |
"އެއް", | |
"ދެ", | |
"ތިން", | |
"ހަތަރު", | |
"ފަސް", | |
"ހަ", | |
"ހަތް", | |
"އަށް", | |
"ނުވަ", | |
] | |
tens = [ | |
"", | |
"ދިހަ", | |
"ވިހި", | |
"ތިރީސް", | |
"ސާޅިސް", | |
"ފަންސާސް", | |
"ފަސްދޮޅަސް", | |
"ހަތްދިހަ", | |
"އަށްޑިހަ", | |
"ނުވަދިހަ", | |
] | |
tens_exceptions ={ | |
10:"ދިހަ", | |
11: "އެގާރަ", | |
12:"ބާރަ", | |
13:"ތޭރަ", | |
14:"ސާދަ", | |
15: "ފަނަރަ", | |
16: "ސޯޅަ", | |
17:"ސަތާރަ", | |
18:"އަށާރަ", | |
20:"ވިހި", | |
19:"ނަވާރަ", | |
21: "އެކާވީސް", | |
22:"ބާޥީސް", | |
23: "ތޭވީސް", | |
24:"ސައުވީސް", | |
25: "ފަންސަވީސް", | |
26: "ސައްބީސް", | |
27: "ހަތާވީސް", | |
28: "އަށާވީސް", | |
29: "ނަވާވީސް", | |
} | |
function convertTens(input_value){ | |
output_string = "" | |
//split for easy manipulation | |
ones_value = input_value % 10 | |
tens_value = Math.floor(input_value / 10) | |
//console.log(ones_value,tens_value) | |
if (tens_value > 2 || tens_value < 1){ | |
//add the value of tens | |
output_string += tens[tens_value] + " " | |
output_string += ones[ones_value] + " " | |
} | |
else { | |
output_string += tens_exceptions[input_value] | |
} | |
return output_string | |
} | |
function convertWords(input_number){ | |
genString = "" | |
input_str_number = input_number | |
input_str_number = input_str_number.padStart(5,0) | |
var ten_thousands = parseInt(input_str_number.substring(0,2)) | |
var hundreds = input_str_number.substring(2,3) | |
var tens = input_str_number.substring(3,5) | |
//console.log(ten_thousands,hundreds,tens) | |
//get the value of ten thousands and thousands | |
if (convertTens(ten_thousands).trim() != ""){} | |
genString += convertTens(ten_thousands) + " ހާސް " | |
if (ones[hundreds].trim() != ""){ | |
genString += ones[hundreds] + " ސަތޭކަ " | |
} | |
if (convertTens(tens).trim() != ""){ | |
genString += convertTens(tens) | |
} | |
return genString | |
} | |
function convertToDhivehi(input_text){ | |
laari = "00" | |
dhivehi_str = "" | |
//remove all non digit values except . and / | |
var input_text = input_text.replace("/","."); | |
var stripped_text = input_text.replace(/[^\d.-]/g, ''); | |
//split / to get rufiyaa and laari | |
var split_text = stripped_text.split(".") | |
int_part = split_text[0] | |
if (split_text.length > 1){ | |
laari = split_text[1] | |
} | |
dhivehi_str += convertWords(int_part) + " ރުފިޔާ " | |
if (convertTens(laari).trim() != ""){ | |
dhivehi_str += convertTens(laari) + " ލާރި " | |
} | |
return "("+dhivehi_str+")" | |
} | |
text = convertToDhivehi("98756/85") | |
console.log(text) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment