Как сделать подсчет кубатуры?
Помогите пожалуйста правильно вывести формулу подсчета кубатуры
нужно чтобы пользователь в инпут вводил 25 а подсчет был как 0.025. Как это возможно реализовать? let rav = 0.0+thickness * 0. +width * height * quantity * price (пример 0.025*0.100*5*10*3200 = результат будет 400) <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Калькулятор</title> <style> body{ padding-left: 50px; } #result{ display: block; margin-top: 50px; margin-left: 100px; width: 250px; height: 5em; background: #ccc; font-size: 35px; color: red; text-align: center; line-height: 5em; } </style> </head> <body> <h1>Калькулятор М³</h1> <br> Толщина: <input type="text" placeholder="миллиметры" id="thickness"> <br><br> Ширина: <input type="text" placeholder="миллиметры" id="width"><br><br> Длинна: <input type="text" placeholder="метры" id="height"><br><br> Количество: <input type="text" placeholder="шт" id="quantity"><br><br> Цена: <input type="text" placeholder="цена" id="price"><br><br> <button id="count">Расчитать</button> <div id="result"></div> <script> document.querySelectorAll('input').forEach( a => a.addEventListener('input', e => e.target.value = e.target.value.replace(/\D/,'')) ) document.querySelector('#count').onclick = function(){ let thickness = document.querySelector('#thickness').value let width = document.querySelector('#width').value let height = document.querySelector('#height').value let quantity = document.querySelector('#quantity').value let price = document.querySelector('#price').value let result = document.querySelector('#result') let rav = 0.0+thickness * 0. +width * height * quantity * price result.innerHTML = rav; } </script> </body> </html> |
Сколько в метре миллиметров? На сколько надо разделить введенное чтобы получить в метрах? Разве это JS проблемы?
|
Точно, спасибо!
Ответ будет: let rav = thickness / 1000 * width / 1000 * height * quantity * price еще одно, а как сделать если я не хочу оставить пустую строку цены, как сделать чтобы оно подсчитало без цены? |
А что оно должно посчитать, если цены нет?
|
да, оно подсчитает только кубатуру, а если указать цену тогда выходит цена за куб!
решил сам - if(rav == 0){ rav = thickness / 1000 * width / 1000 * height * quantity result.innerHTML = rav } |
Цитата:
Определять надо, если не введено, то значение установить как 1, расчет как и с ценой, только вывод значений или кубы, или метры. А в полях запретить ввод первого числа равный 0. |
Часовой пояс GMT +3, время: 22:45. |