Roundup total and multiply again jquery calculator

走远了吗. 提交于 2019-12-24 17:48:01

问题


I have a few modifications I need for my cost calculator:

  1. Is there a way to add a Math.celi to the no of cans so it rounds up to the nearest whole number, providing the minimum cans needed?

  2. What ever the minimum required cans are, can the cost reflect that by multiplying by 18.23 and giving the real amount?

    $('input').keyup(function () { // run anytime the value changes
    
    
     var firstValue = parseFloat($('#width').val()); // get value of field
     var secondValue = parseFloat($('#height').val());
     var thirdValue = parseFloat($('#per-can').val()); // convert it to a float
     var forthValue = parseFloat($('#cost').val());
     var fithValue = parseFloat($('#size').val());
    
     var canCount = firstValue * secondValue / thirdValue;
    
     $('#added').html((canCount * forthValue).toFixed(2));
     $('#cans').html(canCount.toFixed(2));
    
     if (Math.ceil(canCount) < 2) {
     $('#error').html("Need at least 1!");
     } else {
     $('#error').empty();   
     }
    
     });
    

http://jsfiddle.net/5xzSy/504/ thanks

来源:https://stackoverflow.com/questions/25803495/roundup-total-and-multiply-again-jquery-calculator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!