Last active
November 12, 2024 06:20
-
-
Save aorborc/56e2a86ee921a253b9a787fc1b2cc08a to your computer and use it in GitHub Desktop.
Revisions
-
aorborc revised this gist
May 28, 2022 . 1 changed file with 10 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -19,9 +19,16 @@ string String.TwoDigitWords(int num) { first_digit_str = num.toString().substring(0,1); first_digit = first_digit_str.toLong(); if(num % 10 == 0) { amount_in_words = double_words.get(first_digit - 2); } else { second_digit_str = num.toString().substring(1); second_digit = second_digit_str.toLong(); amount_in_words = double_words.get(first_digit - 2) + " " + single_words.get(second_digit - 1); } } } return amount_in_words; -
aorborc revised this gist
May 26, 2022 . 3 changed files with 52 additions and 40 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,44 +1,12 @@ string String.Amount2Words(float amount) { //amount.frac() not working for long numbers paise_str = amount.toString().getSuffix("."); if(paise_str != "") { paise_amount = paise_str.toLong(); paise_str = " and "+ thisapp.String.TwoDigitWords(paise_amount) + " paise"; } rupee_str = String.RupeeInWords(amount.toLong()); return rupee_str + " rupees" + paise_str + " only"; } 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ string String.RupeeInWords(int amount) { amount_in_words = ""; //Crores -> 9 or more Digits if((amount / 10000000).toLong() > 0) { crore_num = (amount / 10000000).toLong(); crore_str = thisapp.String.Amount2Words(crore_num); crore_num_len = crore_num.toString().length(); rest_amount = amount.toString().substring(crore_num_len).toLong(); rest_str = thisapp.String.Amount2Words(rest_amount); amount_in_words = crore_str + " Crores " + rest_str; } //Lakhs -> 7 Digits else if((amount / 100000).toLong() > 0) { lakh_word = thisapp.String.TwoDigitWords((amount / 100000).toLong()) + " lakhs"; rest_str = amount.toString().substring(2); amount_in_words = lakh_word + " " + thisapp.String.Amount2Words(rest_str.toLong()); } //Thousands -> 5 Digits else if((amount / 1000).toLong() > 0) { thou_word = thisapp.String.TwoDigitWords((amount / 1000).toLong()) + " thousand"; rest_of_word = thisapp.String.ThreeDigitWords((amount % 1000).toLong()); amount_in_words = thou_word + " " + rest_of_word; } else if(amount.toLong() > 99) { amount_in_words = thisapp.String.ThreeDigitWords(amount.toLong()); } else if(amount.toLong() > 0) { amount_in_words = thisapp.String.TwoDigitWords(amount.toLong()); } return amount_in_words; } 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ Amount = 12341234567.89; rupee_text = thisapp.String.Amount2Words(Amount); //Output //One thousand Two hundred and Thirty Four Crores Twelve lakhs Thirty Four thousand Five hundred and Sixty Seven rupees and Eighty Nine paise only -
aorborc revised this gist
May 26, 2022 . 1 changed file with 16 additions and 9 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,13 @@ string String.Amount2Words(float amount) { amount_in_words = ""; paise_amount_str = ""; paise_amount = amount.toString().getSuffix(".").toLong(); if(paise_amount > 0) { paise_amount_str = " and " + thisapp.String.TwoDigitWords(paise_amount) + " paise"; } //Crores -> 9 or more Digits if((amount / 10000000).toLong() > 0) { @@ -25,13 +30,15 @@ string String.Amount2Words(float amount) { thou_word = thisapp.String.TwoDigitWords((amount / 1000).toLong()) + " thousand"; rest_of_word = thisapp.String.ThreeDigitWords((amount % 1000).toLong()); amount_in_words = thou_word + " " + rest_of_word + " rupees" + paise_amount_str + " only"; } else if(amount.toLong() > 99) { amount_in_words = thisapp.String.ThreeDigitWords(amount.toLong()) + " rupees" + paise_amount_str+ " only"; } else if(amount.toLong() > 0) { amount_in_words = thisapp.String.TwoDigitWords(amount.toLong()) + " rupees" + paise_amount_str+ " only" ; } return amount_in_words; } -
aorborc created this gist
May 26, 2022 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ string String.Amount2Words(float amount) { amount_in_words = ""; paise_amount = amount.toString().getSuffix(".").toLong(); paise_amount_str = thisapp.String.TwoDigitWords(paise_amount) ; //Crores -> 9 or more Digits if((amount / 10000000).toLong() > 0) { crore_num = (amount / 10000000).toLong(); crore_str = thisapp.String.Amount2Words(crore_num.toDecimal()); crore_num_len = crore_num.toString().length(); rest_amount = amount.toString().substring(crore_num_len).toDecimal(); rest_str = thisapp.String.Amount2Words(rest_amount); amount_in_words = crore_str + " Crores " + rest_str; } //Lakhs -> 7 Digits else if((amount / 100000).toLong() > 0) { lakh_word = thisapp.String.TwoDigitWords((amount / 100000).toLong()) + " lakhs"; rest_str = amount.toString().substring(2); amount_in_words = lakh_word + " " + thisapp.String.Amount2Words(rest_str.toDecimal()); } //Thousands -> 5 Digits else if((amount / 1000).toLong() > 0) { thou_word = thisapp.String.TwoDigitWords((amount / 1000).toLong()) + " thousand"; rest_of_word = thisapp.String.ThreeDigitWords((amount % 1000).toLong()); amount_in_words = thou_word + " " + rest_of_word + " rupees and " + paise_amount_str + " paise only"; }else if (amount.toLong() > 99) { amount_in_words = thisapp.String.ThreeDigitWords((amount).toLong()) + " rupees and " + paise_amount_str + " paise only"; }else if ( amount.toLong() > 0 ) { amount_in_words = thisapp.String.TwoDigitWords((amount).toLong()) + " rupees and " + paise_amount_str + " paise only"; } return amount_in_words; } 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ string String.ThreeDigitWords(int num) { amount_in_words = ""; if(num > 99) { single_words = {"One","Two","Three","Four","Five","Six","Seven","Eight","Nine"}; first_digit_str = num.toString().substring(0,1); first_digit = first_digit_str.toLong(); amount_in_words = amount_in_words + single_words.get(first_digit - 1) + " hundred"; second_digit_str = num.toString().substring(1); second_digit = second_digit_str.toLong(); if(second_digit > 0) { amount_in_words = amount_in_words + " and " + thisapp.String.TwoDigitWords(second_digit); } } return amount_in_words; } 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ string String.TwoDigitWords(int num) { double_words = {"Twenty","Thirty","Forty","Fifty","Sixty","Seventy","Eighty","Ninety"}; teen_words = {"Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"}; single_words = {"One","Two","Three","Four","Five","Six","Seven","Eight","Nine"}; //num = 99; amount_in_words = ""; if(num > 0) { if(num < 10) { amount_in_words = single_words.get(num - 1); } else if(num < 20) { amount_in_words = teen_words.get(num - 10); } else if(num < 100) { first_digit_str = num.toString().substring(0,1); first_digit = first_digit_str.toLong(); second_digit_str = num.toString().substring(1); second_digit = second_digit_str.toLong(); amount_in_words = double_words.get(first_digit - 2) + " " + single_words.get(second_digit - 1); } } return amount_in_words; }