Created
September 3, 2018 15:18
-
-
Save RioChndr/1353a2bd78b3c21f348e3f1b8cf2a4d7 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/tewixod
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
var nilai = 10000000.4123; | |
function number_format(v, titikPemisah = ",", komaDesimal = "."){ | |
var rev = v.toString().split("."); | |
//memisah angka dengan desimal (gk maslah jika tidak ada desimal) | |
var newVal = ""; | |
//membuat variable penyimpanan angka baru | |
var rev1 = rev[0].toString().split("").reverse(); | |
// membalikkan angka dari 10000 menjadi 00001 dan menjadikannya array | |
rev1.map((i, index)=>{ | |
//melakukan looping terhadap setiap array | |
if(index % 3 == 0 && index != 0){ | |
// apabila pengulangan nya (index) dibagi 3 tidak mendapatkan sisa maka akan ditambah kan titik | |
newVal += titikPemisah; | |
//penambahan titik pemisah | |
} | |
newVal += i; | |
//memasukkan (i) ke variable baru | |
}) | |
var revNewVal = newVal.split("").reverse().join(""); | |
// membalikkan varible tempat penyimpanan angka baru | |
if(rev[1]){ | |
revNewVal += komaDesimal+rev[1]; | |
// menambah koma desimal apabila ada desimal | |
} | |
return revNewVal; //mengembalikan nilai value baru | |
} | |
var test = number_format(nilai, ".", ","); | |
console.log(test); | |
/** Created By : Rio Chandra **/ | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">var nilai = 10000000.4123; | |
function number_format(v, titikPemisah = ",", komaDesimal = "."){ | |
var rev = v.toString().split("."); | |
//memisah angka dengan desimal (gk maslah jika tidak ada desimal) | |
var newVal = ""; | |
//membuat variable penyimpanan angka baru | |
var rev1 = rev[0].toString().split("").reverse(); | |
// membalikkan angka dari 10000 menjadi 00001 dan menjadikannya array | |
rev1.map((i, index)=>{ | |
//melakukan looping terhadap setiap array | |
if(index % 3 == 0 && index != 0){ | |
// apabila pengulangan nya (index) dibagi 3 tidak mendapatkan sisa maka akan ditambah kan titik | |
newVal += titikPemisah; | |
//penambahan titik pemisah | |
} | |
newVal += i; | |
//memasukkan (i) ke variable baru | |
}) | |
var revNewVal = newVal.split("").reverse().join(""); | |
// membalikkan varible tempat penyimpanan angka baru | |
if(rev[1]){ | |
revNewVal += komaDesimal+rev[1]; | |
// menambah koma desimal apabila ada desimal | |
} | |
return revNewVal; //mengembalikan nilai value baru | |
} | |
var test = number_format(nilai, ".", ","); | |
console.log(test); | |
/** Created By : Rio Chandra **/</script></body> | |
</html> |
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
var nilai = 10000000.4123; | |
function number_format(v, titikPemisah = ",", komaDesimal = "."){ | |
var rev = v.toString().split("."); | |
//memisah angka dengan desimal (gk maslah jika tidak ada desimal) | |
var newVal = ""; | |
//membuat variable penyimpanan angka baru | |
var rev1 = rev[0].toString().split("").reverse(); | |
// membalikkan angka dari 10000 menjadi 00001 dan menjadikannya array | |
rev1.map((i, index)=>{ | |
//melakukan looping terhadap setiap array | |
if(index % 3 == 0 && index != 0){ | |
// apabila pengulangan nya (index) dibagi 3 tidak mendapatkan sisa maka akan ditambah kan titik | |
newVal += titikPemisah; | |
//penambahan titik pemisah | |
} | |
newVal += i; | |
//memasukkan (i) ke variable baru | |
}) | |
var revNewVal = newVal.split("").reverse().join(""); | |
// membalikkan varible tempat penyimpanan angka baru | |
if(rev[1]){ | |
revNewVal += komaDesimal+rev[1]; | |
// menambah koma desimal apabila ada desimal | |
} | |
return revNewVal; //mengembalikan nilai value baru | |
} | |
var test = number_format(nilai, ".", ","); | |
console.log(test); | |
/** Created By : Rio Chandra **/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment