Round to nearest even dollar

Stimulsoft Reports.NET discussion
jrSD
Posts: 23
Joined: Wed Jun 10, 2015 8:10 pm

Re: Round to nearest even dollar

Post by jrSD »

So sorry. Yes, I believe it to be VB.NET script.
Jan
Posts: 1265
Joined: Thu Feb 19, 2009 8:19 am

Re: Round to nearest even dollar

Post 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.
jrSD
Posts: 23
Joined: Wed Jun 10, 2015 8:10 pm

Re: Round to nearest even dollar

Post 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...
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Round to nearest even dollar

Post 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.
jrSD
Posts: 23
Joined: Wed Jun 10, 2015 8:10 pm

Re: Round to nearest even dollar

Post 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...
jrSD
Posts: 23
Joined: Wed Jun 10, 2015 8:10 pm

Re: Round to nearest even dollar

Post by jrSD »

!!SOLVED!!
Here is my solution:

{CINT((ROUND(Parts.CutPartWidth+0.00001,4)+1)/2)*2}
Ivan
Posts: 960
Joined: Thu Aug 10, 2006 1:37 am

Re: Round to nearest even dollar

Post 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 3905 times
Thank you.
jrSD
Posts: 23
Joined: Wed Jun 10, 2015 8:10 pm

Re: Round to nearest even dollar

Post 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?
Ivan
Posts: 960
Joined: Thu Aug 10, 2006 1:37 am

Re: Round to nearest even dollar

Post 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.
Attachments
MyRound.mrt
(3.69 KiB) Downloaded 344 times
jrSD
Posts: 23
Joined: Wed Jun 10, 2015 8:10 pm

Re: Round to nearest even dollar

Post 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!!
Post Reply