Shaun
Shaun

Reputation: 99

How can I always round up decimal values to the nearest integer value?

On a report I have the following code for a field:

=Sum([PartQty]*[ModuleQty])

Example results are 2.1 and 2.6. What I need is for these value to round up to the value of 3. How can I change my field code to always round up the results of my current expression?

Upvotes: 5

Views: 18516

Answers (4)

Alan Falcone
Alan Falcone

Reputation: 1

Volunteer for a Fire Dept. They get paid for any call over an hour 1.0. I took the date difference with a "." format change from ":". (1:30 = 1.3)

Duration: (DateDiff("n",[StartTimeCalc],[EndTimeCalc]))\60 & Format((DateDiff("n",[StartTimeCalc],[EndTimeCalc])) Mod 60,"\.00")

So now the duration under an hour shows as "0". A duration of 12.1 which would be "13" shows as "12".

Duration1: Int(([Duration]-0.6)+0.59)

Table Snippet

Upvotes: 0

isxaker
isxaker

Reputation: 9496

Test this: Round(yournumber + 0.5, 0)

Upvotes: 2

RLH
RLH

Reputation: 15698

This is an old Access trick I learned a very long time ago, and it makes use of the way Access handles fractional, negative numbers. Try this:

-Int(-[DecimalValue])

It's odd, but it will always round your numbers up to the nearest whole number.

Upvotes: 8

Sam Holder
Sam Holder

Reputation: 32946

you could do

=Int(Sum([PartQty]*[ModuleQty]))+1

I think. That would get the Int part of the sum (2) and then add 1. you might need to be a little more clever as this will probably give you 3 even if the sum is exactly 2, which is probably not what you want.

not tested it but something along these lines might work (access syntax is not that great, but should give you the right idea) :

Iif(Sum([PartQty]*[ModuleQty])-Int(Sum([PartQty]*[ModuleQty]))=0,
     Sum([PartQty]*[ModuleQty]),
     Int(Sum([PartQty]*[ModuleQty]))+1)

Upvotes: 1

Related Questions