• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 561
  • Last Modified:

Code to round up to the nearest 100

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
DatabaseDek
Asked:
DatabaseDek
3 Solutions
 
NikolasGCommented:
Hi
Try (Int(thefield ) / 100) *100
Hope it helps.
0
 
peter57rCommented:
Use..

round((50+Field)/100,0)*100
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
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
Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
F IgorCommented:
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
 
Mike DSolution ConsultantCommented:
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
 
NikolasGCommented:
Hi
I ve misplaced the / symbol in the previous post.
Try (Int(thefield / 100) *100)
Hope it helps.
0
 
DatabaseDekAuthor Commented:
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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now