I need to round down to the nearest quarter hour (or .25 in decimal) via Javascript and have not come across any appropriate code yet. Anyone have a solution?

Recommended Answers

All 4 Replies

If you want to always round down to the quarter

((int)(d/.25))*.25

If you want to round to the nearest quarter

Math.round(d/.25)*.25

I'm missing something as it's not working for me.

Sorry, I'm used to working in Java, not Javascript. Try

Math.floor( d/.25)*.25

where 'd' is just the variable.

Who would have thought it could be that simple. Other examples I found on the web were often quite messy.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.