1

```

function addTwoDigits(n) {
var result;
result = Math.floor(n/10) + 10*(n/10-Math.floor(n/10));
console.log(result);
return result;

}
addTwoDigits(29);

``` the output was 10.9999999999999999999999999999999 I wonder why it was not 11 since according to normal way of calculation it should be rounded already but it's not. Is there any hidden computer science thoery behind this?

  • check this [post](http://stackoverflow.com/questions/11832914/round-to-at-most-2-decimal-places-in-javascript). Hope this helps. – jmj Oct 15 '16 at 07:18

1 Answers1

0

put Math.round()

function addTwoDigits(n) {
var result;
result = Math.floor(n/10) + 10*(n/10-Math.floor(n/10));
console.log(Math.round(result));
return result;

}
addTwoDigits(29);

Hope this helps.

Bhavin Shah
  • 2,462
  • 4
  • 22
  • 35
  • tks for sparing your time, but I actually mean was that i wanna know Why the result was 10.99999999. I do know we could use Math.round alreaduy :D – NewbieCodeGuy Oct 15 '16 at 07:39