1 2 Previous Next 17 Replies Latest reply on Apr 15, 2016 6:34 AM by DemersGlass

# Looking for a calculation or script to round up to the next even integer

Hi,  Using Filemaker Pro 14 -  I am working with an established set of records, trying to add in an estimating page.  I'm stuck now getting our measurements (window glass) to round up to the next even integer to calculate the cost by total square feet..

For instance the measurements of a window would be 47.5" x 39.75" .  Our cost and customer pricing is charged by the even inches so we would base our charge on 48" x 40".  In Excel, I found a function to do this calculation, and found a custom function for Filemaker Pro Advanced, but so far am unable to determine a calculation or script that isn't quite cumbersome and prone to errors to do this.

Can anyone help me with this?

Barbara

• ###### 1. Re: Looking for a calculation or script to round up to the next even integer

Perhaps a calculation field like this:

Int( The_Number_Field / 2 +.5 ) * 2

-

Anders

• ###### 2. Re: Looking for a calculation or script to round up to the next even integer

Round ( myNumber + 0.499 ; 0 )

• ###### 3. Re: Looking for a calculation or script to round up to the next even integer

Stephen Huston wrote:

Round ( myNumber + 0.499 ; 0 )

Good one – nearest, not next (as I read this)…

• ###### 5. Re: Looking for a calculation or script to round up to the next even integer

Ceiling works: "to round up to the next even integer" the calculation would look something like:

If (Mod (Ceiling (MyNumber;2) = 0; MyNumber; MyNumber + 1)

would give you 48 if the entered value was either 46.5  or 47.5 which would be the next even number.

• ###### 6. Re: Looking for a calculation or script to round up to the next even integer

I'm not sure "even" in this case means "evenly divisible by two". The OP may have just meant "integer".

But if "even" means "evenly divisible by two", then Mod is additionally needed, as you point out. However, you would need to do something like this:

Let ( [

myNumberAsInt = Ceiling ( myNumber )

] ;

If ( Mod ( myNumberAsInt ; 2 ) = 0 ; myNumberAsInt ; myNumberAsInt + 1 )

)

because just using the raw number will result in a fractional part.

• ###### 7. Re: Looking for a calculation or script to round up to the next even integer

Int ( myNumber ) + ( 2 - Mod ( myNumber ; 2 ) ) should do it.

• ###### 8. Re: Looking for a calculation or script to round up to the next even integer

Mike,

Thanks for the correction. As soon as I posted it I knew that I forgot to put in Ceiling (MyNumber) and Ceiling (MyNumber) + 1 which I had in my Data Viewer but neglected to type out. Am I correct in thinking that there would then be no residuals?

• ###### 9. Re: Looking for a calculation or script to round up to the next even integer

If by “residuals”, you mean fractional parts, then yes, they’d be eliminated by the Ceiling function.

• ###### 10. Re: Looking for a calculation or script to round up to the next even integer

Let ( [

myNumberAsInt = Ceiling ( myNumber )

] ;

If ( Mod ( myNumberAsInt ; 2 ) = 0 ; myNumberAsInt ; myNumberAsInt + 1 )

)

This can be

Let ( [

myNumberAsInt = Ceiling ( myNumber )

] ;

myNumberAsInt + Mod ( myNumberAsInt ; 2 )

)

• ###### 11. Re: Looking for a calculation or script to round up to the next even integer

Nice!

• ###### 12. Re: Looking for a calculation or script to round up to the next even integer

This is how I would do it,

use mod() function with a divisor of 1 to return the decimal part of the number

then test for zero do not need to round UP

If ( Mod(\$num1;1)=0 ; Truncate(\$num1;0) ; Truncate(\$num1;0) + 1)

Now I will use ceiling()

• ###### 13. Re: Looking for a calculation or script to round up to the next even integer

Here is a simple mathematical solution to round up to the next even number:

ceiling( \$Number / 2 ) * 2

gives:

0 -> 0

0.1 -> 2

1.0 -> 2

1.5 -> 2

2 -> 2

3 -> 4

4 -> 4

5 -> 6

6 -> 6

7 -> 8

8 -> 8

9 -> 10

10 -> 10

You can generalise the function to round up to the next \$roundUpToNumber like this:

ceiling( \$Number / \$roundUpToNumber ) * \$roundUpToNumber

Thus to round up a number to the next 5

ceiling( \$Number / 5 ) * 5

gives:

0 -> 0

1 -> 5

2 -> 5

3 -> 5

4 -> 5

5 -> 5

6 -> 10

7 -> 10

8 -> 10

9 -> 10

10 -> 10

• ###### 14. Re: Looking for a calculation or script to round up to the next even integer

This may be the best here.

The rounding theory is also in the first reply from andersmonsen

1 2 Previous Next