Maor
Maor

Reputation: 1

JS, Why Math.Round takes 2 Arguments

Inside one JS file I saw:

Math.round(timeEngine.timeLeft, 10)

I've checked many documentations (some are mentioned here) and all mention that this function takes one argument, so what the second argument (10) is referring to?

https://www.w3schools.com/jsref/jsref_round.asp

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round

Upvotes: -1

Views: 551

Answers (2)

Lazaro Nascimento
Lazaro Nascimento

Reputation: 41

Math.round() function in JavaScript takes only one parameter. But round() function is implemented differently in other languages. For example, round() function in Python takes two parameters. First parameter is number and second parameter is digits. It's the same as Number.toFixed() function in JavaScript. I think it is possible that Python developers who is not familiar with JavaScript may write like this. I hope this can help you understand.

Upvotes: 0

Dhammika
Dhammika

Reputation: 81

The Math.round() function takes one argument, which is the number that you want to round. The second argument that you saw in the code (10) is not part of the Math.round() function, and it is likely being used for a different purpose.

Upvotes: 0

Related Questions