Apply Rounding Rules

Hi,
I want perform price rounding operation as follows

1. When Price > 0 and Price < 500 make it multiple of 10
2. When Price > 0 and Price < 500 end price with 1.1
3. When Price > 0 and Price < 500 make it multiple of 10 and end with 1.1

It can be to round to nearest, round up or round down operation,

For eg.
With 3 rd point operation round to nearest--> I should get -->
Old Value      Round to near                   Round Up                                  Round Down
-8.00                -8.00                                 -8.00                                   -8.00
0.00                  0.00                                   0.00                                   0.00
0.50                11.01                                  11.01                                  1.01
5.00                11.01                                  11.01                                  1.01
12.99              11.01                                  21.01                                  1.01
79.99              81.01                                101.01                                 69.01

Please provide some hints, formulas. with sql or vb 6 program

RETAILREALMAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

fds_fatboyCommented:
Can you rephrase the question for the hard of thinking.

Conditions 1, 2 and 3 are all the same. i.e. When Price > 0 and Price < 500

Youer examples do not tally with statements 1, 2 or 3.
0
PaulCaswellCommented:
Generally If you look at integer division for rounding it becomes a little clearer.

1. (x / r) * r

essentially 'compresses' the scale of all numbers by a factor 'r'. I.e. any exact multiple of 'r' and all numbers following it up to - but not including - the next multiple of r becomes the factor.

E.G.

(x / 10) * 10

forces 0,1,...,9 to become 1.

2. x % r (or x MOD r)

delivers the fractional part (remainder) of function '1'.

Between these two functions and an 'if' you can generally achieve any form of rounding you want.

e.g. working in pence, rounding to the nearest pound with 50p rounding up, use:

((x / 100) * 100) + (x % 100 >= 5?1:0)

Good luck!

Paul
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.