Yes, you are right, I copied some code that I had used that
required
quarter-rounding.
The required code should be
<cfset halfRound = round(originalNumber*2)/2>
The following test show it works.
<cfoutput>
<table>
<cfloop from="0" to="1.5" step="0.01" index="iA">
<tr>
<td>#iA#</td>
<td>#round(iA*2)/2#</td>
</tr>
</cfloop>
</table>
</cfoutput>
BKBK wrote:
>
Should be simple, try the following:
> <cfset quarterRound =
round(originalNumber*4)/4>
>
> You can immediately see that this is wrong. You're
dividing by 4 and so will
> get numbers ending in .25. These are incorrect, as the
result must be a whole
> number or a whole number and a half.
>
> Here is a possible answer. First, think of the number of
whole quarters in a
> number. For example, there are 2 whole quarters in
0.749, but 3 in 0.75 and 3
> in 0.99. The number of whole quarters in the list is as
follows:
>
> .01 - .24 ---> 0
> .25 - .50 ---> 1 - 2
> .51 - .74 ---> 2
> .75 - 1.0 ---> 3 - 4
> 1.01 - 1.24 ---> 4
> 1.25 - 1.50 ---> 5 - 6
> 1.51 -1.74 ---> 6
> 1.75 - 2.0 ---> 7 - 8
>
> The formula for the number of whole quarters in the
number n is
>
> fix(x*4)
>
[int(x*4) is good, too, but we'll go with fix()]
>
> We now seek a function which we can apply to these whole
numbers N to get the
> required results. A possibility is
>
> round(N/2)*0.5
>
> When we apply it to the list of whole numbers, we get
>
> 0 ---> 0
> 1 - 2 ---> 0.5
> 3 - 4 ---> 1
> 5 - 6 ---> 1.5
> 7 - 8 ---> 2
>
> You will see that that is the required result. What we
therefore need is the
> composite of both functions. It is
>
> round(fix(originalNumber*4)/2)*0.5
>
>
>
>
>
>
>