Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
514 views
in Technique[技术] by (71.8m points)

rounding - round to nearest .25 javascript

I want to convert all numbers to the nearest .25

So...

5 becomes 5.00
2.25 becomes 2.25
4 becomes 4.00
3.5 becomes 3.50

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Here’s an implementation of what rslite said:

var number = 5.12345;
number = (Math.round(number * 4) / 4).toFixed(2);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...