Page 2 of 3

Re: Round to nearest even dollar

Posted: Tue Sep 22, 2015 3:42 pm
by jrSD
So sorry. Yes, I believe it to be VB.NET script.

Re: Round to nearest even dollar

Posted: Wed Sep 23, 2015 3:34 am
by Jan
Hello,
jrSD wrote:So sorry. Yes, I believe it to be VB.NET script.
What about this expression:

Code: Select all

{Round(Parts.CutPartWidth, 0)}
Thank you.

Re: Round to nearest even dollar

Posted: Wed Sep 23, 2015 3:46 pm
by jrSD
Thank you Jan! Yes, this rounding command works on my system. However, I need a command that always rounds UP & to the nearest EVEN number. Thank you in advance for any additional insight on this matter. I am stumped...

Re: Round to nearest even dollar

Posted: Thu Sep 24, 2015 9:43 am
by HighAley
Hello.

Sorry, but it's possible either round up or to the nearest even number.
Could you specify what do you need to get from 3.5 and 4.5 values?

Thank you.

Re: Round to nearest even dollar

Posted: Thu Sep 24, 2015 3:45 pm
by jrSD
Aleksey Andreyanov wrote:Hello.

Sorry, but it's possible either round up or to the nearest even number.
Could you specify what do you need to get from 3.5 and 4.5 values?

Thank you.

So, I purchase a certain material that has a pricing structure wherein all pricing is calculated based on the nearest WHOLE EVEN number.
3.2=4
4.1=6

In MS Access I am able to get the results I need in a query by using the following method:

NewColumn: round([Parts.CutPartWidth]+0.00001,1)

RoundedEven: (Int((-[NewColumn])/2))*-2

Thanks for the help...

Re: Round to nearest even dollar

Posted: Thu Sep 24, 2015 8:47 pm
by jrSD
!!SOLVED!!
Here is my solution:

{CINT((ROUND(Parts.CutPartWidth+0.00001,4)+1)/2)*2}

Re: Round to nearest even dollar

Posted: Thu Sep 24, 2015 11:05 pm
by Ivan
Hello,

Sorry, maybe we did not exactly understood your question.

From your first post: "6.75 it needs to be rounded to 6. If it's 7.25 it needs to be rounded to 8."
From your previous post: "the 3.2 is rounded to 4, the 4.1 is rounded to 6". Therefore 6.75 must be rounded to 8.

Please specify - which rule is correct ?
numbers.png
numbers.png (12.89 KiB) Viewed 3902 times
Thank you.

Re: Round to nearest even dollar

Posted: Fri Sep 25, 2015 3:39 pm
by jrSD
Ivan wrote:Hello,

Sorry, maybe we did not exactly understood your question.

From your first post: "6.75 it needs to be rounded to 6. If it's 7.25 it needs to be rounded to 8."
From your previous post: "the 3.2 is rounded to 4, the 4.1 is rounded to 6". Therefore 6.75 must be rounded to 8.

Please specify - which rule is correct ?
numbers.png
Thank you.

Ivan...So sorry. I did not look closely enough at 'MikeC's original post. I should have created a new thread from the outset. My need was to always round UP to the nearest EVEN. As such the following syntax is fulfilling my needs:

{CINT((ROUND(Parts.CutPartWidth+0.00001,4)+1)/2)*2}

6.75=8
7.75=8

Is there a better way to accomplish this?

Re: Round to nearest even dollar

Posted: Sat Sep 26, 2015 7:26 am
by Ivan
Hello,
jrSD wrote:Is there a better way to accomplish this?
If you need to use this expression in several places, it is better to describe it as a function, and use this function in expressions.
For example, you can add following function into the report, on the Code tab of designer:

Code: Select all

		Function MyRound(ByVal num As Double) As Double
			MyRound = CInt((Math.Round(num+0.00001,4)+1)/2)*2
		End Function
and then use this function in expressions:

Code: Select all

{MyRound(3.75)}
{MyRound(4.1)}
Thank you.

Re: Round to nearest even dollar

Posted: Mon Sep 28, 2015 6:14 pm
by jrSD
Ivan wrote:Hello,
jrSD wrote:Is there a better way to accomplish this?
If you need to use this expression in several places, it is better to describe it as a function, and use this function in expressions.
For example, you can add following function into the report, on the Code tab of designer:

Code: Select all

		Function MyRound(ByVal num As Double) As Double
			MyRound = CInt((Math.Round(num+0.00001,4)+1)/2)*2
		End Function
and then use this function in expressions:

Code: Select all

{MyRound(3.75)}
{MyRound(4.1)}
Thank you.

Brilliant! Thank you very much!!