Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Apply Rounding Rules

Posted on 2005-03-11
4
Medium Priority
?
206 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
2 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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 …
No other job is as rewarding and demanding as building an iPhone app is. It is not really in the hands of the developer for the success of an iPhone app. Many factors operate jointly for every iOS application's success in the market.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Starting up a Project

577 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