問題:
I need a utility function that takes in an integer value (ranging from 2 to 5 digits in length) that rounds up to the next multiple of 5 instead of the nearest multiple of 5. Here is what I got:我需要一個實用函數,它接受一個整數值(長度爲 2 到 5 位數字),該值向上取整爲 5 的下一個倍數而不是最接近的 5 的倍數。這是我得到的:
function round5(x)
{
return (x % 5) >= 2.5 ? parseInt(x / 5) * 5 + 5 : parseInt(x / 5) * 5;
}
When I run round5(32)
, it gives me 30
, where I want 35.當我運行round5(32)
,它給了我30
,我想要 35 。
When I run round5(37)
, it gives me 35
, where I want 40.當我運行round5(37)
,它給了我35
,我想要 40 。
When I run round5(132)
, it gives me 130
, where I want 135.當我運行round5(132)
,它給了我130
,我想要 135 。
When I run round5(137)
, it gives me 135
, where I want 140.當我運行round5(137)
,它給了我135
,我想要 140 。
etc...等等...
How do I do this?我該怎麼做呢?