Created
February 25, 2022 08:38
-
-
Save yogasw/c9fa09ea65994d60c4e33b25cdc77ff0 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
let number1 = 91532 | |
let number2 = 1174885093020 | |
let number3 = 373520 | |
let number4 = 53772457827.00 | |
let number5 = 212999166433.00 | |
function printCurrency(number) { | |
// Nine Zeroes for Trillion | |
let value = Math.abs(Number(number)) >= 1.0e+12 | |
? (Math.abs(Number(number)) / 1.0e+12).toFixed(1) + " Triliun" | |
: Math.abs(Number(number)) >= 1.0e+9 | |
? (Math.abs(Number(number)) / 1.0e+9).toFixed(1) + " Miliar" | |
// Six Zeroes for Millions | |
: Math.abs(Number(number)) >= 1.0e+6 | |
? (Math.abs(Number(number)) / 1.0e+6).toFixed(1) + " Juta" | |
// Three Zeroes for Thousands | |
: Math.abs(Number(number)) >= 1.0e+3 | |
? (Math.abs(Number(number)) / 1.0e+3).toFixed(1) + " Ribu" | |
: Math.abs(Number(number)); | |
console.log(value) | |
} | |
printCurrency(number1) | |
printCurrency(number2) | |
printCurrency(number3) | |
printCurrency(number4) | |
printCurrency(number5) | |
// Expected Result | |
// 91.5 Ribu | |
// 1.17 Triliun | |
// 373 Ribu | |
// 53.7 Miliar | |
// 212 Miliar | |
//Output | |
// 91.5 Ribu | |
// 1.2 Triliun | |
// 373.5 Ribu | |
// 53.8 Miliar | |
// 213.0 Miliar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment