Skip to content

Instantly share code, notes, and snippets.

@yogasw
Created February 25, 2022 08:37
Show Gist options
  • Save yogasw/0fcc97487a4c3151ae12cda4e258b68b to your computer and use it in GitHub Desktop.
Save yogasw/0fcc97487a4c3151ae12cda4e258b68b to your computer and use it in GitHub Desktop.
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment