0
round of this code not use any function ,loop and math function javascript?
var arr = 440.4;
7 Réponses
+ 1
Mirielle ~~ is not exactly round, more like Math.trunc().
Interesting, but I can't find a shortcut equivalent to Math.round.
https://code.sololearn.com/WfMgCx17ytBg/?ref=app
0
Mirielle
For negative numbers, ~~ gives different result from floor.
But you're right. If it works, and it is not for something critical, over-analyzing is not necessary.
The rounding rule to round up or keep the same if digit is odd or even number before 5 makes it rounding what it is. no way around that.
0
Mirielle
I was looking at Math.round and I felt that "add if odd is followed by 5" rule was not implemented for negative values.
It seems like a design choice. Rounding, floor, ceil are really fiddly topics.
https://en.wikipedia.org/wiki/Rounding#
0
arr - arr % 1