Неверное деление целых чисел
Здравствуйте друзья!
Делаю себе калькулятор подсчета чувствительности к инсулину. 500 делю на суточную дозу инсулина 28 = 17,86 17,86 делю на 12 и должен получить 1,49 (с округлением) а получаю 1,42 Подскажите пожалуйста, что не так?? Вот скрипт $(function() { $('input').keyup(function(){ updateTotal(); }); var updateTotal = function () { var input2 = parseInt($('#tab_id2').val()) || null; var total = (500 / input2).toFixed(2); if (input2) { $('#total_id_1').val(total); }; var input1 = parseInt($('#total_id_1').val()) || null; var total = (input1 / 12).toFixed(2); if (input1) { $('#total_id_2').val(total); } } }); 500÷<input type="number" id="tab_id2" />= <input type="number" id="total_id_1"/>гр. <br> <input type="number" id="total_id_2" />ХЕ И еще такой вопрос, можно ли сделать так, чтобы при удалении значения с input все остальные значения удалялись? Заранее большое спасибо! |
Alexprom,
<!DOCTYPE html> <html> <head> <title>Untitled</title> <meta charset="utf-8"> <style type="text/css"> </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script> $(function() { $('input').on('input', () => updateTotal()); var updateTotal = function () { var input2 = parseInt($('#tab_id2').val()); var d = h = ''; if (input2) { d = (500 / input2); h = (d / 12).toFixed(2); d = d.toFixed(2); }; $('#total_id_1').val(d); $('#total_id_2').val(h); } }); </script> </head> <body> 500÷<input type="number" id="tab_id2" />=<br> <output id="total_id_1"></output> гр. <br> <output id="total_id_2"></output> ХЕ </body> </html> |
Цитата:
Цитата:
|
Спасибо Рони, вы как всегда помогаете! Хорошего вам дня!
|
Часовой пояс GMT +3, время: 11:23. |