Javasctipt multiplying 2 fields [duplicate]











up vote
-2
down vote

favorite













This question already has an answer here:




  • Is floating point math broken?

    27 answers



  • Round to at most 2 decimal places (only if necessary)

    59 answers




I have three text inputs, two where the user enters figures and one which shows the result of the two text boxes multiplied together.



function calculate() {
var myBox1 = document.getElementById('box1').value;
var myBox2 = document.getElementById('box2').value;
var result = document.getElementById('result');
var myResult = myBox1 * myBox2;
document.getElementById('result').value = myResult;
}


This works fine, however is there a way to show the multiplied number/field to 2 decimal places?



Eg, rather than showing 46.800000000000004 it would show 46.9?










share|improve this question















marked as duplicate by CertainPerformance javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 10 at 22:58


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















    up vote
    -2
    down vote

    favorite













    This question already has an answer here:




    • Is floating point math broken?

      27 answers



    • Round to at most 2 decimal places (only if necessary)

      59 answers




    I have three text inputs, two where the user enters figures and one which shows the result of the two text boxes multiplied together.



    function calculate() {
    var myBox1 = document.getElementById('box1').value;
    var myBox2 = document.getElementById('box2').value;
    var result = document.getElementById('result');
    var myResult = myBox1 * myBox2;
    document.getElementById('result').value = myResult;
    }


    This works fine, however is there a way to show the multiplied number/field to 2 decimal places?



    Eg, rather than showing 46.800000000000004 it would show 46.9?










    share|improve this question















    marked as duplicate by CertainPerformance javascript
    Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

    StackExchange.ready(function() {
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function() {
    $hover.showInfoMessage('', {
    messageElement: $msg.clone().show(),
    transient: false,
    position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
    dismissable: false,
    relativeToBody: true
    });
    },
    function() {
    StackExchange.helpers.removeMessages();
    }
    );
    });
    });
    Nov 10 at 22:58


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

















      up vote
      -2
      down vote

      favorite









      up vote
      -2
      down vote

      favorite












      This question already has an answer here:




      • Is floating point math broken?

        27 answers



      • Round to at most 2 decimal places (only if necessary)

        59 answers




      I have three text inputs, two where the user enters figures and one which shows the result of the two text boxes multiplied together.



      function calculate() {
      var myBox1 = document.getElementById('box1').value;
      var myBox2 = document.getElementById('box2').value;
      var result = document.getElementById('result');
      var myResult = myBox1 * myBox2;
      document.getElementById('result').value = myResult;
      }


      This works fine, however is there a way to show the multiplied number/field to 2 decimal places?



      Eg, rather than showing 46.800000000000004 it would show 46.9?










      share|improve this question
















      This question already has an answer here:




      • Is floating point math broken?

        27 answers



      • Round to at most 2 decimal places (only if necessary)

        59 answers




      I have three text inputs, two where the user enters figures and one which shows the result of the two text boxes multiplied together.



      function calculate() {
      var myBox1 = document.getElementById('box1').value;
      var myBox2 = document.getElementById('box2').value;
      var result = document.getElementById('result');
      var myResult = myBox1 * myBox2;
      document.getElementById('result').value = myResult;
      }


      This works fine, however is there a way to show the multiplied number/field to 2 decimal places?



      Eg, rather than showing 46.800000000000004 it would show 46.9?





      This question already has an answer here:




      • Is floating point math broken?

        27 answers



      • Round to at most 2 decimal places (only if necessary)

        59 answers








      javascript forms input






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 22:59









      GBlodgett

      7,12741329




      7,12741329










      asked Nov 10 at 22:57









      Designer

      192




      192




      marked as duplicate by CertainPerformance javascript
      Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 10 at 22:58


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






      marked as duplicate by CertainPerformance javascript
      Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 10 at 22:58


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.































          active

          oldest

          votes






















          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes

          Popular posts from this blog

          Xamarin.iOS Cant Deploy on Iphone

          Glorious Revolution

          Dulmage-Mendelsohn matrix decomposition in Python