Last active
January 25, 2020 13:14
-
-
Save davodaslanifakor/d8ec0de6cc8f6980cc1792ceb13e7bd3 to your computer and use it in GitHub Desktop.
convert rial to persian letters toman
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
// include https://github.com/mahmoud-eskandari/NumToPersian | |
get_persian(val) { | |
// return "صفر تومان" if val is 0 | |
if(Number(val) === 0) return 'صفر تومان'; | |
// check value for change separated value to number | |
let non_separated_val = isNaN(val) ? Number(val.split(',').join('')) :val; | |
// get "toman" part if number is bigger than 9 rial | |
let toman_part = non_separated_val > 9 ? Num2persian(Math.floor(non_separated_val / 10)) + ' تومان ' : ''; | |
// get "rial" part if number remainder of the division by 10 is bigger than 10 | |
let rial_part = non_separated_val % 10 > 0 ? Num2persian(non_separated_val % 10) + ' ریال ' : ''; | |
// return result by 2 statement :: | |
// 1. statement one :: toman_part and rial_part exists | |
// 2. statement two :: toman_part exists or rial_part exists | |
return (toman_part && rial_part) ? (toman_part + ' و ' + rial_part) : toman_part ? toman_part : rial_part ; | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment