Created
August 17, 2020 06:09
-
-
Save bymustfa/e35de3dcd975710b2f91959776a248dd 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
function numToWord(number) { | |
const list1 = ['', 'bir', 'iki', 'üç', 'dört', 'beş', 'altı', 'yedi', 'sekiz', 'dokuz', 'on', 'onbir ', 'oniki ', 'onüç', 'ondört', 'onbeş', 'onaltı', 'onyedi', 'onsekiz', 'ondokuz']; | |
const list2 = ['', '', 'yirmi', 'otuz', 'kırk', 'elli', 'altmış', 'yetmiş', 'seksen', 'doksan']; | |
const list3 = ['', 'bin', 'milyon', 'milyar', 'trilyon', 'katrilyon']; | |
let string = ''; | |
for (let i = 0; i < list3.length; i++) { | |
let number = number % (100 * Math.pow(1000, i)); | |
if (Math.floor(number / Math.pow(1000, i)) !== 0) { | |
if (Math.floor(number / Math.pow(1000, i)) < 20) { | |
string = list1[Math.floor(number / Math.pow(1000, i))] + list3[i] + '' + string; | |
} else { | |
string = list2[Math.floor(number / (10 * Math.pow(1000, i)))] + '' + list1[Math.floor(number / Math.pow(1000, i)) % 10] + list3[i] + '' + string; | |
} | |
} | |
number = number % (Math.pow(1000, i + 1)); | |
if (Math.floor(number / (100 * Math.pow(1000, i))) !== 0) string = list1[Math.floor(number / (100 * Math.pow(1000, i)))] + 'yüz' + string; | |
} | |
return 'Yalnız ' + string.replace(/biryüz/gm, 'yüz').replace(/^birbin/, 'bin'); | |
} | |
console.log(numToWord(159357852654)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment