Solved

Code to round up to the nearest 100

Posted on 2012-03-15
7
541 Views
Last Modified: 2012-06-21
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
Comment
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
  • Learn & ask questions
7 Comments
 
LVL 6

Expert Comment

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

Assisted Solution

by:peter57r
peter57r earned 200 total points
ID: 37724132
Use..

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

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 200 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 13

Expert Comment

by:F Igor
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

by:Mike D
ID: 37724194
How about:
get modulo of original number to the number you want to round to
subtract this from number you want to round to
add result to original number

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>";
}
?>

Open in new window


JD

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

Assisted Solution

by:NikolasG
NikolasG earned 100 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

by:DatabaseDek
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

729 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