Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想将一个数字四舍五入到最接近的 1/4。例如,如果我有3.21,我会将其四舍五入为3.25,或者如果我有3.46,我将四舍五入为3.50。我想为此编写一个方法,但我不确定如何。
3.21
3.25
3.46
3.50
尝试这个:(number / 0.25).round * 0.25
(number / 0.25).round * 0.25