0

https://github.com/fernandofig/jquery-formatcurrency http://bendewey.com/code/formatcurrency/demo/

I am using this demo on my site so that when a user enters digits, it will be converted to a currency format.

So now my user can enter the dollar amount and the plugin will auto format for that currency, but my users will be entering cents instead of dollars. See the desired and current scenarios below

Example a user enters: 1200 — Output: $1,200.00 — Desired output $12.00

How can I modify to assume that my customer is typing in the cents instead of dollars.

Omar
  • 2,726
  • 2
  • 32
  • 65

1 Answers1

0

Rory's Solution worked for me. Check it out https://jsfiddle.net/cqnbnhxo/

var theField = $("#mw_amount");
$(".submit").click( function(){
    var theFieldVal = $("#mw_amount").val();
    var formatedVal = '$' + (theFieldVal / 100).toFixed(2);
    $("#mw_amount").val(formatedVal);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
type a number then submit to see cents formatted to dollars <br>
<input type="text" value="100" id="mw_amount">
<input type="submit" class="submit">
Omar
  • 2,726
  • 2
  • 32
  • 65