0
I’m having trouble displaying the result in converting decimal to binary.
When I do so by defining 2020 in the decimal variable, returns the correct value that is 11111100100
var decimal = 2020;
var binario = decimal.toString(2);
alert(binario);
//retorna 11111100100
However, when I use HTML input, the result is not as expected. It always returns the same value as I type in the input.
<input type="text" id="decimal-input">
<input type="button" value="CONVERTER" onclick="convertDec()">
function convertDec() {
var decimal = document.getElementById('decimal-input').value;
var binario = decimal.toString(2);
alert(binario);
//retorna sempre o mesmo valor que foi digitado no input do ID decimal-input, e não retorna no formato binário
}
Where am I going wrong?
Thanks, it helped a lot !!
– user145275