-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (27 loc) · 1.23 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
module.exports = (nominal) => {
let bilangan = null
let koma = null
let arrayNominal = ('' + parseInt(nominal)).split('').map(Number)
if (arrayNominal.length > 3 && arrayNominal.length <= 6) {
bilangan = 'Ribu'
koma = arrayNominal.slice(arrayNominal.length - 3).slice(0, 2).join('')
arrayNominal.splice(arrayNominal.length - 3, arrayNominal.length - 1)
}
if (arrayNominal.length > 6 && arrayNominal.length <= 9) {
bilangan = 'Juta'
koma = arrayNominal.slice(arrayNominal.length - 6).slice(0, 2).join('')
arrayNominal.splice(arrayNominal.length - 6, arrayNominal.length - 1)
}
if (arrayNominal.length > 9 && arrayNominal.length <= 12) {
bilangan = 'Milyar'
koma = arrayNominal.slice(arrayNominal.length - 9).slice(0, 2).join('')
arrayNominal.splice(arrayNominal.length - 9, arrayNominal.length - 1)
}
if (arrayNominal.length > 12 && arrayNominal.length <= 15) {
bilangan = 'Trilyun'
koma = arrayNominal.slice(arrayNominal.length - 12).slice(0, 2).join('')
arrayNominal.splice(arrayNominal.length - 12, arrayNominal.length - 1)
}
const nominalOutput = koma === '00' ? Math.floor(arrayNominal.join('')) : `${arrayNominal.join('')},${koma}`
return `${nominalOutput} ${bilangan}`
}