?
Solved

Apply Rounding Rules

Posted on 2005-03-11
4
Medium Priority
?
202 Views
Last Modified: 2010-04-17
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

0
Comment
Question by:RETAILREALM
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 10

Expert Comment

by:fds_fatboy
ID: 13517873
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
 
LVL 16

Accepted Solution

by:
PaulCaswell earned 1000 total points
ID: 13518550
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

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Six Sigma Control Plans
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question