Forum Moderators: coopster

Message Too Old, No Replies

round() sort of!

need to do better than round()

         

henry0

9:44 pm on Dec 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am looking for more rounding variations
Here is what I need implementing:

if ends by .25 or <.25 the result will end by .00

if ends by > .25 or <.75 the result will end by .50

if ends by >.75 the result will end by .00 + 1

I may write a function
but I am afraid that on a busy site it could impact on performance
Any suggestions?

jdMorgan

10:34 pm on Dec 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If normal rounding rounds down for <x.50 and up for >x.50, then:

Multiply by 2.
Round the number using the usual function.
Divide by 2.

The end result will be rounded to quarters instead of halves.

Jim

henry0

10:56 pm on Dec 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thank you, just implemented, logic, light strain
makes so much sense.

I use it for a rating system (total_rating/total_vote) where I need more definitions; that just does it.