Parse Float and toFixed()

1915 views javascript

I have my code and it is working, but I'm trying to add the parseFloat option and 'toFixed()' to 2 decimal places. I'm confused on where these 2 lines of code should be placed. I created a unit conversion website that would convert the number of inches a user inputs and converts it to feet.

<!DOCTYPE html>
  <meta charset="UTF-8">
  <center><title>Unit Coversion Table</title><center>

<div id="question">
  <h2>Unit Convertor</h2>
  <p>Enter a Quanity of Inches: <input id="userinches" type="number" /> </p>
</div>  <!-- End of question div section -->

<div id="conversion">
    function feet() {
      var userinches = document.getElementById('userinches').value;
      doOuput('The answer is ', userinches * 0.0833);

    function doOuput(val, unit) {
      document.getElementById('results').innerHTML = val + unit;
</div>  <!-- End of conversion div section -->

  <button type="button" id="buttonft" onclick="feet();">Feet</button>
</div> <!-- End of buttons div section -->

<div id="results"></div>  <!-- End of results div section -->


answered question

1 Answer


you can add it in the feet() function where you get the value of the input and convert it to feet:

function feet() {
  var userinches = document.getElementById('userinches').value;
  var feetValue = parseFloat(userinches * 0.0833).toFixed(2);
  doOuput('The answer is ', feetValue);

posted this

Have an answer?


Please login first before posting an answer.