jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes int to Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "int to """ Watch "int to """ New topic

int to ""

Melinda Wilson
Ranch Hand

Joined: Jul 05, 2001
Posts: 35
I have a method that returns an integer. I am testing this integer value for null, if null I return 0 (zero). I do not want 0 to be displayed instead a blank/empty string. How do I do this?
<%= monthlyPaymentPlan.getInstallmentCount() > 0 ?monthlyPaymentPlan.getInstallmentCount() : 0 %>
Thank you.
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
If I understand you correctly then you can't return an empty string from a method that is declared to return an int. You could just test it after it is returned and then display the appropriate repsonse or change the method to return a string and if you have an int value then use toString to change it to a string value to be returned.
If I didn't understand your question let me know

Sun Certified Programmer for the Java� 2 Platform

Melinda Wilson
Ranch Hand

Joined: Jul 05, 2001
Posts: 35
The rest of my post didn't get posted here is the method:
monthlyPaymentPlan.getInstallmentCount() > 0 ? monthlyPaymentPlan.getInstallmentCount() : 0
Lets see if the toString will do it.
Fei Ng
Ranch Hand

Joined: Aug 26, 2000
Posts: 1242
toString will turn it into a string "0" not empty space.
Can do a if statement to test it and just System.out.print("");
I agree. Here's the link: http://aspose.com/file-tools
subject: int to ""
It's not a secret anymore!