## Only Allow Even Numbers, Round to .5 etc

## Only Allow Even Numbers, Round to .5 etc

**Guest**(visitor)

(OP)

I have a program that only allows numbers following the rules as below...

ie 1st line of rule....and number between 2 and 2.99 can only bo 2.02 2.04 2.06 2.08 2.10 2.12 ...... 2.98 etc

ie last line only allows 110 120 130 140 .........etc

+ lines as well

Would appreciate some help ..Is there an easy way to carry out this type of thing

it's got me beaten...@!@!@!!@

Regards TROBT

'From 2.02 to 3.00 one tick is equal to 0.02.

'From 3.05 to 4.00 one tick is equal to 0.05.

'From 4.1 to 6.0 one tick is equal to 0.1.

'From 6.2 to 10.0 one tick is equal to 0.2.

'From 10.5 to 20.0 one tick is equal to 0.5.

'From 21 to 30 one tick is equal to 1.

'From 32 to 50 one tick is equal to 2.

'From 55 to 100 one tick is equal to 5.

'From 110 to 1000 one tick is equal to 10.

ie 1st line of rule....and number between 2 and 2.99 can only bo 2.02 2.04 2.06 2.08 2.10 2.12 ...... 2.98 etc

ie last line only allows 110 120 130 140 .........etc

+ lines as well

Would appreciate some help ..Is there an easy way to carry out this type of thing

it's got me beaten...@!@!@!!@

Regards TROBT

'From 2.02 to 3.00 one tick is equal to 0.02.

'From 3.05 to 4.00 one tick is equal to 0.05.

'From 4.1 to 6.0 one tick is equal to 0.1.

'From 6.2 to 10.0 one tick is equal to 0.2.

'From 10.5 to 20.0 one tick is equal to 0.5.

'From 21 to 30 one tick is equal to 1.

'From 32 to 50 one tick is equal to 2.

'From 55 to 100 one tick is equal to 5.

'From 110 to 1000 one tick is equal to 10.

## RE: Only Allow Even Numbers, Round to .5 etc

What's the rule for numbers less than 2 or greater than 1000?

I'd probably construct a table for these rules.

Skip,

_{ Just traded in my OLD subtlety... for a NUance!}## RE: Only Allow Even Numbers, Round to .5 etc

## CODE

`Private Function TickRound(myNum As Double) As Double Dim tick As Double If myNum > 2 Then tick = 0.02 If myNum > 3 Then tick = 0.05 If myNum > 4 Then tick = 0.1 If myNum > 6 Then tick = 0.2 If myNum > 10 Then tick = 0.5 If myNum > 20 Then tick = 1 If myNum > 30 Then tick = 2 If myNum > 50 Then tick = 5 If myNum > 100 Then tick = 10 tick = 1 / tick TickRound = Round(myNum * tick) / tick End Function`

## RE: Only Allow Even Numbers, Round to .5 etc

Skip,

_{ Just traded in my OLD subtlety... for a NUance!}## RE: Only Allow Even Numbers, Round to .5 etc

But don't you wanna do something with 51 to 54?

"Trying is the first step to failure..." - Homer

## RE: Only Allow Even Numbers, Round to .5 etc

Mind you the Banker's rounding in my code does mean we don't meet this interpretation. So, the following minor update shoukd work. Note also that this is simply an illustrative solution; the numbers representing where the intervals can obviously be changed to whatever you like.

## CODE

`Private Function TickRound(myNum As Double) As Double Dim tick As Double If myNum >= 2 Then tick = 0.02 If myNum >= 3 Then tick = 0.05 If myNum >= 4 Then tick = 0.1 If myNum >= 6 Then tick = 0.2 If myNum >= 10 Then tick = 0.5 If myNum >= 20 Then tick = 1 If myNum >= 30 Then tick = 2 If myNum >= 50 Then tick = 5 If myNum >= 100 Then tick = 10 tick = 1 / tick ' Rounding Up TickRound = (Int((myNum * tick)) / tick) + (1 / tick) End Function`

## RE: Only Allow Even Numbers, Round to .5 etc

Guest(visitor)Strongm..

Once again thanks for your support....

I had tried ... Round(myNum * tick) / tick ...but realised it did not work in all cases

Your extra refinement seems to have done the trick..

Thanks again ,much appreciated

Robert