Created
August 9, 2022 13:17
-
-
Save Bhavya2502/8413a0e6af783ad18e72419eca47ad09 to your computer and use it in GitHub Desktop.
Convert Very Large Numbers to Words for both Indian as well as International Numbers
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
/* Link to YouTube Video - https://www.youtube.com/watch?v=u1gzAcwmlpo*/ | |
Number_To_Words = LAMBDA(Number, [Indian_or_InterN], | |
LET( | |
Option, IF(ISOMITTED(Indian_or_InterN), 1, Indian_or_InterN), | |
l, LEN(Number), | |
L_1, SEQUENCE(19), | |
R_1, VSTACK( | |
"One", | |
"Two", | |
"Three", | |
"Four", | |
"Five", | |
"Six", | |
"Seven", | |
"Eight", | |
"Nine", | |
"Ten", | |
"Eleven", | |
"Twelve", | |
"Thirteen", | |
"Fourteen", | |
"Fifteen", | |
"Sixteen", | |
"Seventeen", | |
"Eighteen", | |
"Nineteen" | |
), | |
L_2, SEQUENCE(8, , 2), | |
R_2, VSTACK( | |
"Twenty", | |
"Thirty", | |
"Forty", | |
"Fifty", | |
"Sixty", | |
"Seventy", | |
"Eighty", | |
"Ninety" | |
), | |
L_3, IF( | |
Option = 1, | |
VSTACK("Ones", "Hundred", "Thousand", "Lakhs", "Crores"), | |
VSTACK("Thousand", "Million", "Billion", "Trillion") | |
), | |
A, SEQUENCE(l), | |
B, MID(Number, A, 1), | |
C, IF( | |
l <= 2, | |
0, | |
SCAN(--ISODD(l), A, LAMBDA(x, y, IF(y = l - 2, 1, IF(x = 0, 1, 0)))) | |
), | |
D, TEXTSPLIT( | |
TEXTJOIN( | |
"", | |
TRUE, | |
IF( | |
Option = 1, | |
IF(C, B & ",", B), | |
IF(MOD(A + 1, 3) = MOD(l, 3), B, B & ",") | |
) | |
), | |
, | |
",", | |
TRUE | |
) * 1, | |
E, MAP( | |
D, | |
LAMBDA(x, | |
IFNA( | |
XLOOKUP( | |
x, | |
L_1, | |
R_1, | |
TEXTJOIN( | |
"-", | |
TRUE, | |
XLOOKUP(LEFT(x, 1) * 1, L_2, R_2), | |
IFERROR(XLOOKUP(RIGHT(x, 1) * 1, L_1, R_1), "") | |
) | |
), | |
"" | |
) | |
) | |
), | |
F, SEQUENCE(ROWS(E), , ROWS(E), -1), | |
G, IF( | |
Option = 1, | |
IFS( | |
E = "", | |
"", | |
F = 1, | |
"", | |
TRUE, | |
IFERROR(INDEX(L_3, F), INDEX(L_3, F - 4)) | |
), | |
IFS( | |
E = "", | |
"", | |
F = 1, | |
"", | |
MOD(F, 2) = 0, | |
"Hundred", | |
TRUE, | |
XLOOKUP(F, SEQUENCE(4, , 3, 2), L_3) | |
) | |
), | |
Final, TRIM(TEXTJOIN(" ", TRUE, E & " " & G)), | |
IF( | |
AND(Option = 1, l > 9), | |
TEXTJOIN( | |
" ", | |
TRUE, | |
Number_To_Words(LEFT(Number, l - 7)), | |
"Crores", | |
Number_To_Words(RIGHT(Number, 7)) | |
), | |
Final | |
) | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Excellent! Thank you for sharing this.