Jump to content
We've recently updated our Privacy Statement, available here ×

print dash when value is ZERO


atmaling
Go to solution Solved by atmaling,

Recommended Posts

HI All,

While using iReport i got one problem.

I am displaying values from a table. column fields are "name","roll","marks".

I want to display dash i.e. "--" when the value of "marks" field is ZERO.

As now I am getting following output.

Name    Roll    Marks

John    51    66

Tom    21    0

Harry    12    0

 

Expected Output

 

I want following OUTPUT

Name    Roll    Marks

John    51    66

Tom    21    --

Harry    12    --

 

 

Please help me

 

Thanks in Advance

Code:
Code:
[code]
Code:
[code]
Code:
[code]
Link to comment
Share on other sites

  • Replies 7
  • Created
  • Last Reply

Top Posters In This Topic

Hmmm

 

perhaps I forgot just a point before equals (answered just from mind, without any iReport/IDE open)

 

try this one:

 

Code:
(BigDecimal.ZERO).equals($F{marks})?"--":$F{marks}.toString()

 

This is just a simple Java comparison.

 

Means:

 

If your field "marks" is BigDecimal Zero than print "--" otherwise print the content of your field "marks"

 

hth now

C-Box

Link to comment
Share on other sites

  • Solution

Thanks very much friend.

BUt this is not working. Its giving error message as "IncompatibleÂconditionalÂoperandÂtypesÂStringÂandÂBigDecimal"

 

But I did by other method and its working fine.

I changed the field type "marks" to String and then I wrote following expression in Text field expression

"$F{marks}.equals("0") ? "--" : $F{marks}"

 

make sure that "marks" field should be String

Link to comment
Share on other sites

  • 1 month later...

I have a similar question to the one above except that I'd like to keep my output as a double. So, my code looks like this:

 

($F{WinnersReturn} == null) ? "N/A" : $F{WinnersReturn}

 

The reason I don't want to use the "toString()" function at the end of $F{WinnersReturn} is because I want to format the output to a percentage if the field is NOT NULL.

I tried tricking it into thinking "N/A" was a double by doing:

new Double("N/A")

but, obviously, that gave me an error while filling.

Thanks in advance,

_ramy

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...