-1

when I calc this value I got a big number like 48.4979898749,

how convert this to 48.49 ???

GawiSh
  • 31
  • 8
  • Oops, marked dups appear wrong. so -> `Math.trunc(48.4979898749 * 100) / 100` – Keith Jun 29 '18 at 21:17
  • Thanks Keith, this helped me, `"48.4979898749.toFixed(2)"` – GawiSh Jun 29 '18 at 21:22
  • 1
    The accepted answer here shows how to get a truncated number or get a rounded number: [Limit the amount of number shown after a decimal place in javascript](https://stackoverflow.com/questions/4256030/limit-the-amount-of-number-shown-after-a-decimal-place-in-javascript). I think the correct duplicate should be this question. – AndrewL64 Jun 29 '18 at 21:22

1 Answers1

1

You could take the number and apply Number#toFixed with the wanted number of digits.

var valuee = document.getElementById("valueNum"),
    result = document.getElementById("res");        

valuee.onkeyup = function () {
    "use strict";
    result.innerHTML = "المبلغ المطلوب " + (valuee.value * 0.0680).toFixed(2) + " دولار";
};
<input type="text" id="valueNum">
<div id="res"></div>
Nina Scholz
  • 376,160
  • 25
  • 347
  • 392
  • 1
    `48.4979898749.toFixed(2)` is '48.50',.. – Keith Jun 29 '18 at 21:19
  • 1
    technically, toFixed(2) converts 48.4979898749 to 48.50, not 48.49 ... but I think the OP wasn't thinking about rounding – CSSBurner Jun 29 '18 at 21:19
  • The accepted answer here shows how to get a truncated number or get a rounded number: [Limit the amount of number shown after a decimal place in javascript](https://stackoverflow.com/questions/4256030/limit-the-amount-of-number-shown-after-a-decimal-place-in-javascript). I think the correct duplicate should be this question. – AndrewL64 Jun 29 '18 at 21:22
  • in the duplicates, there is always a funky converting to number, either by parsing or with `Number`. this answer uses an implicit casting with a number expecting operand. – Nina Scholz Jun 29 '18 at 21:25