Round to nearest even dollar

Stimulsoft Reports.NET discussion
MikeC
Posts: 51
Joined: Mon Jun 07, 2010 3:36 pm

Round to nearest even dollar

Post by MikeC »

I have a field that needs to be rounded to the nearest even number. For example, if the amount is 6.75 it needs to be rounded to 6. If it's 7.25 it needs to be rounded to 8. Which function (or combination) can do that?

Thanks.
Jan
Posts: 1265
Joined: Thu Feb 19, 2009 8:19 am

Round to nearest even dollar

Post by Jan »

Hello Mike,

Try to use following expression:

Code: Select all

{(int)value == value ? (int)value : (int)value + 1}
Thank you.
jrSD
Posts: 23
Joined: Wed Jun 10, 2015 8:10 pm

Re: Round to nearest even dollar

Post by jrSD »

I need to use this function. However, I am not certain how or where to pit this expression...
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Round to nearest even dollar

Post by HighAley »

Hello.

You could use this expression in text of text component.

Thank you.
jrSD
Posts: 23
Joined: Wed Jun 10, 2015 8:10 pm

Re: Round to nearest even dollar

Post by jrSD »

So, if my data source is: {Parts.CutPartWidth} how would I apply such?

When I use the following:

{int(Parts.CutPartWidth) == Parts.CutPartWidth ? int(Parts.CutPartWidth) : int(Parts.CutPartWidth + 1);}

I get 'undeclared 'int'' errors. What am I missing here? Any help is GREATLY appreciated.
Jan
Posts: 1265
Joined: Thu Feb 19, 2009 8:19 am

Re: Round to nearest even dollar

Post by Jan »

Hello,
jrSD wrote:So, if my data source is: {Parts.CutPartWidth} how would I apply such?

When I use the following:

{int(Parts.CutPartWidth) == Parts.CutPartWidth ? int(Parts.CutPartWidth) : int(Parts.CutPartWidth + 1);}

I get 'undeclared 'int'' errors. What am I missing here? Any help is GREATLY appreciated.
Try to use following expression:

Code: Select all

 {(int)Parts.CutPartWidth == Parts.CutPartWidth ? (int)Parts.CutPartWidth : (int)Parts.CutPartWidth + 1}}
p.s. I also correct expression in previous message.

Thank you.
jrSD
Posts: 23
Joined: Wed Jun 10, 2015 8:10 pm

Re: Round to nearest even dollar

Post by jrSD »

Thank you for responding. I am still getting a syntax error though...using:

{(int)Parts.CutPartWidth == Parts.CutPartWidth ? (int)Parts.CutPartWidth : (int)Parts.CutPartWidth + 1}

and also:

{(int)Parts.CutPartWidth == Parts.CutPartWidth ? (int)Parts.CutPartWidth : (int)Parts.CutPartWidth + 1}
Jan
Posts: 1265
Joined: Thu Feb 19, 2009 8:19 am

Re: Round to nearest even dollar

Post by Jan »

Hello,

Second expressions is correct. Can you say which error message you see? Also may be you use VB.NET as script language?

Thank you.
jrSD
Posts: 23
Joined: Wed Jun 10, 2015 8:10 pm

Re: Round to nearest even dollar

Post by jrSD »

The errors i get are as follows:

1. "The error of compilation is found in the 'text' property of the 'Text21' Component: Syntax error."
2. "The error of compilation is found in the 'text' property of the 'Text21' Component: Comma,')', or a valid expression continuation expected.
3. "The error of compilation is found in the 'text' property of the 'Text21' Component: 'int' is not declared. It may be inaccessible due to its protection level.

Thank you very much for any help that could be lent...
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Round to nearest even dollar

Post by HighAley »

Hello.

You didn't specify what language you use.
Do you use VB.NET script language in the report?

Thank you.
Post Reply