Tolong pilih kategori sesuai, jenis posting (diskusi atau bukan) dan sertakan tag/topik yang sesuai seperti komputer, java, php, mysql, dll. Promosi atau posting tidak pada tempatnya akan kami hapus!
- Bagi Anda yang ingin mendaftar, baca link berikut:
http://diskusiweb.com/discussion/50491/how-to-registrasi-diskusiweb-com-baca-ini-terlebih-dahulu
- Cara menyisipkan kode program supaya tampil rapi dan terformat dengan baik di diskusiweb.com: http://www.diskusiweb.com/discussion/50415/cara-menyisipkan-kode-program-di-diskusiweb-com
- Cara posting gambar/image di post Anda: http://www.diskusiweb.com/discussion/47345/cara-menyisipkan-menyertakan-image-pada-posting/p1

Javascript convert to rupiah

ada yg punya fungsi javascript untuk merubah dari angka menjadi satuan rupiah

ex. 10000 -> Rp10.000

Comments

  • Googling aja dan ketik keyword format currency javascript. Banyak tuh tutorialnya. Silhkan dibaca sendiri.
  • function price_format(values)
    {
    values=""+values+"";
    var len=values.length;
    var mod=len % 3;
    if(mod==0) mod =3;
    var divided= len/3;
    divided=parseInt(divided);
    var priceFormat=values.substr(0,mod)+".";
    var pointer=0;
    for(var pointer=0;pointer<divided; pointer++)
    {
    priceFormat=priceFormat+""+values.substr((mod+(pointer*3)),3)+".";
    }
    while(priceFormat.substr(priceFormat.length-1,1)==".")
    {
    priceFormat=priceFormat.substr(0,priceFormat.length-1);
    }
    while(priceFormat.substr(0,1)==".")
    {
    priceFormat=priceFormat.substr(1,priceFormat.length-1);
    }
    priceFormat=priceFormat+",00";
    return priceFormat;
    }
  • di while() aja beres...
  • ...kepanjangan...

    <script>
    total = 1000000;
    ttotal += ""; //jadiin string dolo

    stotal = "";
    while(ttotal.length>3) {
    stotal = "." + ttotal.substr(ttotal.length - 3, 3) + stotal;
    ttotal = ttotal.substring(0, ttotal.length - 3);
    }
    stotal = ttotal + stotal;

    document.write("Rp "+stotal);
    </script>


    sekalian nih kalo mau di eja :

    <script>
    function threedigit(word) {
    eja = Array("Nol","Satu","Dua","Tiga","Empat","Lima","Enam","Tujuh","Delapan","Sembilan");
    while(word.length<3) word = "0" + word;
    word = word.split("");
    a = word[0];b = word[1];c = word[2];
    word = "";
    word += (a!="0" ? (a!="1" ? eja[parseInt(a)] : "Se") : "") + (a!="0" ? (a!="1" ? " Ratus" : "ratus") : "");
    word += " " + (b!="0" ? (b!="1" ? eja[parseInt(b)] : "Se") : "") + (b!="0" ? (b!="1" ? " Puluh" : "puluh") : "");
    word += " " + (c!="0" ? eja[parseInt(c)] : "");
    word = word.replace(/Sepuluh ([^ ]+)/gi, "$1 Belas");
    word = word.replace(/Satu Belas/gi, "Sebelas");
    word = word.replace(/^[ ]+$/gi, "");

    return word;
    }

    function sayit(word) {
    word = word + "";
    thousand = Array("","Ribu","Juta","Milyar","Trilyun");
    cent = word.split(".");
    word = cent[0];
    cent = cent[1] ? cent[1] : "0";

    subword = "";i = 0;
    while(word.length>3) {
    subdigit = threedigit(word.substr(word.length - 3, 3));
    subword = subdigit + (subdigit!="" ? " " + thousand + " " : "") + subword;
    word = word.substring(0, word.length - 3);
    i++;
    }
    subword = threedigit(word) + " " + thousand + " " + subword;
    subword = subword.replace(/^ +$/gi,"");

    word = (subword=="" ? "NOL" : subword.toUpperCase()) + " RUPIAH";
    subword = threedigit(cent);
    cent = (subword=="" ? "" : " ") + subword.toUpperCase() + (subword=="" ? "" : " SEN");
    return word + cent;
    }

    document.write(sayit(1000000)); //SATU JUTA RUPIAH
    </script>

    sen-nya sudah diitung juga, cuma masih salah, soalnya saya bingung ejaan sen yg bener gimana :D:D:D
    100.50 << ini 50 sen atau 5 sen?

    ...ember dah, lagian di script saya yg pake script di atas sen-nya gak dipake, males benerin...
  • wuiih... siiip
    inilah gunanya diskusiweb
    tanpa banyak capek2 nyeleksi tutorial hasil googling
    source codenya juga bermutu
  • dalam bentuk function lebih sedep ;)

    function rupiah(value)
    {

    value += '';
    x = value.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
    x1 = x1.replace(rgx, '$1' + '.' + '$2');
    }

    return 'Rp ' + x1 + x2 + ",00";
    };
Sign In or Register to comment.