
1. Re: Looking for a calculation or script to round up to the next even integer
andersmonsen Apr 14, 2016 1:31 PM (in response to DemersGlass)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
Stephen Huston Apr 14, 2016 2:09 PM (in response to DemersGlass)Round ( myNumber + 0.499 ; 0 )

3. Re: Looking for a calculation or script to round up to the next even integer
erolst Apr 14, 2016 3:01 PM (in response to Stephen Huston)Stephen Huston wrote:
Round ( myNumber + 0.499 ; 0 )
Good one – nearest, not next (as I read this)…

4. Re: Looking for a calculation or script to round up to the next even integer
Mike_Mitchell Apr 14, 2016 4:30 PM (in response to DemersGlass)How about Ceiling?

5. Re: Looking for a calculation or script to round up to the next even integer
MaxEh Apr 14, 2016 4:36 PM (in response to Mike_Mitchell)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
Mike_Mitchell Apr 14, 2016 4:44 PM (in response to MaxEh)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
jurgmay Apr 14, 2016 4:49 PM (in response to DemersGlass)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
MaxEh Apr 14, 2016 4:56 PM (in response to Mike_Mitchell)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
Mike_Mitchell Apr 14, 2016 5:02 PM (in response to MaxEh)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
user19752 Apr 14, 2016 5:10 PM (in response to Mike_Mitchell)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
Mike_Mitchell Apr 14, 2016 5:11 PM (in response to user19752)Nice!

12. Re: Looking for a calculation or script to round up to the next even integer
pipopau Apr 14, 2016 5:50 PM (in response to DemersGlass)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
mrwatsongbs Apr 14, 2016 11:27 PM (in response to DemersGlass)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
user19752 Apr 14, 2016 11:45 PM (in response to mrwatsongbs)This may be the best here.
The rounding theory is also in the first reply from andersmonsen