Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# Code to round up to the nearest 100

Posted on 2012-03-15
Medium Priority
554 Views
Hi All

Can I put in a query, Code to round up any numbers up to the nearest 100

I.e 97 = 100
1997= 2000
1421 = 1500
0
Question by:DatabaseDek
[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

LVL 6

Expert Comment

ID: 37724131
Hi
Try (Int(thefield ) / 100) *100
Hope it helps.
0

LVL 77

Assisted Solution

peter57r earned 800 total points
ID: 37724132
Use..

round((50+Field)/100,0)*100
0

LVL 85

Accepted Solution

Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 800 total points
ID: 37724138
You can do this:

-100 * Int( [Amount] / -100)

(Thanks to Allen Browne for the basics on this: http://allenbrowne.com/round.html)

To use this in a Query, you would do something like this in the design grid:

MyNewValue: -100 * Int(YourAmount)/-100)

This would be in the Name row of the query design grid, and would produce a new column named MyNewValue.
0

LVL 13

Expert Comment

ID: 37724155
In access the function floor() doesn't exists (it would make the job easily),
It's my way to do that:

int(([value]-1)/100)*100+100

I.e:

97:   int(96/100)*100+100 = 0*100+100 = 100
1997: int(1996/100)*100+100 = 19*100+100 = 2000
1421: int(1420/100) *100+100 = 14*100+100 =1500
1400: int(1399/100) *100+100 = 13*100+100 =1400
0

LVL 6

Expert Comment

ID: 37724194
get modulo of original number to the number you want to round to
subtract this from number you want to round to

example (in php:)
``````<?
\$all_original_numbers = array(97, 1997, 1421);
\$round_to = 100;

foreach(\$all_original_numbers as  \$original_number){
\$mod_number = \$original_number % \$round_to;
\$diff = \$round_to - \$mod_number;
\$rounded_nr = \$original_number + \$diff;
echo "original nr: " . \$original_number . " - rounded to next " . \$round_to . ": " . \$rounded_nr . "</br>";
}
?>
``````

JD

edit: ups, just realized the topic was Access... but theory is still sound ;)
0

LVL 6

Assisted Solution

NikolasG earned 400 total points
ID: 37724226
Hi
I ve misplaced the / symbol in the previous post.
Try (Int(thefield / 100) *100)
Hope it helps.
0

Author Closing Comment

ID: 37724565
Thank you all

I used

-100*Int([Value]*-0.01)

Dividing in Access always worries me. / by 0 can give an error so I always multiply. Although in the query grid it didn't seem to make any difference.

Thanks again
0

## Featured Post

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
###### Suggested Courses
Course of the Month10 days, 16 hours left to enroll