Calculate Credit

HTML

Set Price: $<input type="text" id="price">
<div>Credit: <span id="credit">0</span></div>
<button id="reload">Calculate</button>

JavaScript

$("#price").change( function(){
    $(this).val( parseInt($(this).val()) );
    if (/\D/g.test(this.value))
    {
        // Filter non-digits from input value.
        $(this).val( this.value.replace(/\D/g, '') );
    }
    
    if( $(this).val() < 4.99)
        $(this).val(4.99);
    
    var rounded = ($("#price").val() / 4.99).toFixed(0);
    $(this).val( (rounded * 4.99).toFixed(2) );
    $("#credit").text( rounded );
});