Hi
I have a rounding problem that I cannot seem to hack through.
99% of the time the entry in a field (which has to be calculated) is either an integer or a precise half - i.e. 10 or 10.5 for instance.
Occasionally the computation goes to 10.0001 or 10.49998 where the environment has peculiarities.
I need to round either to an integer or to a half, but it isn't as simple as rounding up or rounding down.
If the value is between 10.750 and 11.250 I would want to round to 11 but if it was between 11.251 and 11.749 I would want to round to 11.5.
The issue is not fixed to these numbers since the whole number could be anything.
I am currently using
and this rounds down to the half. If I change the 2 to -2 it rounds up to the half. If I change the 2 to 4 it does the same but to the quarter.
I think I need a sort of if test which says if the value after the decimal point is between x and y then round down to the nearest half or if between a and b then round up to the nearest half.
But I might be trying to create a sledge hammer to crack a nut.
Any suggestions would be most welcome - and yes I know you shouldn't store a calculated field but in this instance there are very good reasons why!
Thanks in anticipation
Best wishes
I have a rounding problem that I cannot seem to hack through.
99% of the time the entry in a field (which has to be calculated) is either an integer or a precise half - i.e. 10 or 10.5 for instance.
Occasionally the computation goes to 10.0001 or 10.49998 where the environment has peculiarities.
I need to round either to an integer or to a half, but it isn't as simple as rounding up or rounding down.
If the value is between 10.750 and 11.250 I would want to round to 11 but if it was between 11.251 and 11.749 I would want to round to 11.5.
The issue is not fixed to these numbers since the whole number could be anything.
I am currently using
Code:
Me.txtNumRound = (Int(Me.txtNum * 2)) / 2
I think I need a sort of if test which says if the value after the decimal point is between x and y then round down to the nearest half or if between a and b then round up to the nearest half.
But I might be trying to create a sledge hammer to crack a nut.
Any suggestions would be most welcome - and yes I know you shouldn't store a calculated field but in this instance there are very good reasons why!
Thanks in anticipation
Best wishes