Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
154
rated 0 times [  159] [ 5]  / answers: 1 / hits: 77886  / 13 Years ago, thu, may 26, 2011, 12:00:00



Can someone give me an idea how can i round off a number to the nearest 0.5.

I have to scale elements in a web page according to screen resolution and for that i can only assign font size in pts to 1, 1.5 or 2 and onwards etc.



If i round off it rounds either to 1 decimal place or none.
How can i accomplish this job?


More From » javascript

 Answers
21

Write your own function that multiplies by 2, rounds, then divides by 2, e.g.



function roundHalf(num) {
return Math.round(num*2)/2;
}

[#92042] Tuesday, May 24, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tayla

Total Points: 681
Total Questions: 102
Total Answers: 108

Location: Marshall Islands
Member since Tue, Sep 21, 2021
3 Years ago
tayla questions
Fri, Mar 5, 21, 00:00, 3 Years ago
Wed, Oct 28, 20, 00:00, 4 Years ago
Thu, Apr 9, 20, 00:00, 4 Years ago
;