Results 1 to 2 of 2

Thread: [ASK] How to set of input text automaticly as currency format

  1. #1
    Join Date
    Mar 2013

    [ASK] How to set of input text automaticly as currency format

    please guy help me. i have just already learn about javasciprt. and i have this source code

    <script language="javaScript" type="text/javascript">
    function showpay() {
    if ((document.calc.loan.value == null || document.calc.loan.value.length == 0) ||
    (document.calc.months.value == null || document.calc.months.value.length == 0)
    (document.calc.rate.value == null || document.calc.rate.value.length == 0))
    { document.calc.pay.value = "Incomplete data";
    var amt = parseFloat(document.calc.loan.value);
    var month = parseFloat(document.calc.months.value);
    var intr = parseFloat(document.calc.rate.value);
    var nilai1 = intr/100/12;
    var nilai2 = (1+nilai1);
    var nilaix = Math.pow(nilai2,-month);
    var nilai3 = 1-nilaix;
    var final = amt*(nilai1/nilai3);

    document.getElementById("total").innerHTML = "Angsuran/bulan : <strong>"+final.toFixed(2)+"</strong>";

    // payment = principle * monthly interest/(1 - (1/(1+MonthlyInterest)*Months))


    // -->
    <form name="calc" method="post" action="">
    <h3><?php _e($title); ?> </h3>

    <div class="form_row clearfix">
    <label> <?php _e('Pinjaman');?> : </label> <input type="text" name="loan" class="textfield" />
    <div class="form_row clearfix">
    <label><?php _e('Jmh Bln');?> : </label>
    <input type="text" name="months" class="textfield" />
    <div class="form_row clearfix" >
    <label> <?php _e('Bunga');?> (%): </label> <input type="text" name="rate" class="textfield" />
    <div class="form_row clearfix" >
    <p id="total"> </p>
    <input type="button" onclick="showpay()" value="<?php _e('Hitung');?>" class="btn_input_highlight" />

    The question is i want to change the format of user input for example , user put 10000000 automaticly change to 10.000.000. but when processed to calculation script its still number as 10000000

  2. #2
    Join Date
    Oct 2010
    Versailles, France
    Use a regular expression with something like this :
    	return (this|0).toFixed(2).replace(/(\d)(?=(\d{3})+\b)/g,'$1 ');}
    // Use 
    var i=12345678,j;
    alert(j=i.toMonetaryString()); // 12 345 678.00
    We replace all digit followed by a multiple of three digits and a word boundary by this digit followed with a space (or a comma with a '$1,').
    If you work with integers it's to possible to use points.
    This forms are strings and not Numbers ! Then it's probably useful to save the two forms with conjugated names nmbFinal and strFinal for example.

    To retrieve the number simply remove the spaces (or commas or points)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center

Recent Articles