Last active
April 21, 2022 09:34
-
-
Save bphamict/8b467039bd656574e9e949058e0f7a41 to your computer and use it in GitHub Desktop.
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
| function readGroup(group: string) { | |
| let readDigit = [ | |
| ' Không', | |
| ' Một', | |
| ' Hai', | |
| ' Ba', | |
| ' Bốn', | |
| ' Năm', | |
| ' Sáu', | |
| ' Bảy', | |
| ' Tám', | |
| ' Chín', | |
| ]; | |
| var temp = ''; | |
| if (group == '000') return ''; | |
| temp = readDigit[parseInt(group.substring(0, 1))] + ' Trăm'; | |
| if (group.substring(1, 2) == '0') | |
| if (group.substring(2, 3) == '0') return temp; | |
| else { | |
| temp += ' Lẻ' + readDigit[parseInt(group.substring(2, 3))]; | |
| return temp; | |
| } | |
| else temp += readDigit[parseInt(group.substring(1, 2))] + ' Mươi'; | |
| if (group.substring(2, 3) == '5') temp += ' Lăm'; | |
| else if (group.substring(2, 3) != '0') | |
| temp += readDigit[parseInt(group.substring(2, 3))]; | |
| return temp; | |
| } | |
| function readMoney(num: string) { | |
| if (num == null || num == '') return ''; | |
| let temp = ''; | |
| while (num.length < 18) { | |
| num = '0' + num; | |
| } | |
| let g1 = num.substring(0, 3); | |
| let g2 = num.substring(3, 6); | |
| let g3 = num.substring(6, 9); | |
| let g4 = num.substring(9, 12); | |
| let g5 = num.substring(12, 15); | |
| let g6 = num.substring(15, 18); | |
| if (g1 != '000') { | |
| temp = readGroup(g1); | |
| temp += ' Triệu'; | |
| } | |
| if (g2 != '000') { | |
| temp += readGroup(g2); | |
| temp += ' Nghìn'; | |
| } | |
| if (g3 != '000') { | |
| temp += readGroup(g3); | |
| temp += ' Tỷ'; | |
| } else if ('' != temp) { | |
| temp += ' Tỷ'; | |
| } | |
| if (g4 != '000') { | |
| temp += readGroup(g4); | |
| temp += ' Triệu'; | |
| } | |
| if (g5 != '000') { | |
| temp += readGroup(g5); | |
| temp += ' Nghìn'; | |
| } | |
| temp = temp + readGroup(g6); | |
| console.log('temp', temp); | |
| temp = temp.replace(/Một Mươi/g, 'Mười'); | |
| temp = temp.trim(); | |
| // temp = temp.replace(/Không Trăm/g, ''); | |
| if (temp.startsWith('Không Trăm')) temp = temp.substring(10); | |
| temp = temp.trim(); | |
| temp = temp.replace(/Mười Không/g, 'Mười'); | |
| temp = temp.trim(); | |
| temp = temp.replace(/Mươi Không/g, 'Mươi'); | |
| temp = temp.trim(); | |
| if (temp.indexOf('Lẻ') == 0) temp = temp.substring(2); | |
| temp = temp.trim(); | |
| temp = temp.replace(/Mươi Một/g, 'Mươi Mốt'); | |
| temp = temp.trim(); | |
| let result = | |
| temp.substring(0, 1).toUpperCase() + temp.substring(1).toLowerCase(); | |
| return (result == '' ? 'Không' : result) + ' đồng chẵn'; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment