简体   繁体   中英

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM