0

In this code, I want to check if kcFormula is a float or not.

 function kToc() {
        let userInput2 = parseInt(document.getElementById('in2').value)
        let kcFormula =  userInput2 - 273.15
        res2.innerHTML = kcFormula
    }

If the result is float, I will make some conditions afterwards.

ahyu
  • 1
  • 1
  • 1
    Guaranteed to be a float. You parse as integer and then subtract something with `.15` so it can only be `.85` – VLAZ Apr 06 '23 at 09:54
  • Do you mean this? `const isFloat = !!(kcFormula % 1)` – trincot Apr 06 '23 at 10:01
  • trincot what is '!!'? – ahyu Apr 06 '23 at 10:07
  • it's just `!` aka `not` but twice - you can use `!!` to turn any js variable into a boolean. But remember it uses truthy/falsey, which is why this would work - `!!0` turns into `false`, everything else would turn into `true`. – Plagiatus Apr 06 '23 at 10:13

0 Answers0