This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I just started doing java and one of my assignments require the format for the percent to be displayed but yet when I format it to display as a percent it reverts to just a nondecimal. What am I doing wrong. I have it print prior to format and all looks good(.0525) but when applying the format it shows 5% where is the 5.25%
While the Javadocs aren't entirely clear, you'll probably need to not use the default percentage NumberFormat if it doesn't meet your requirements.
Joined: Feb 14, 2010
The requirements of the assignment require the use of the bigdecimal for the percent. I think this is where the problem is coming from. I placed 2 print statements to show that the decimal is correct but when it goes into the display part of the progam the percent format changes. Is there a way to format the bigdecimal so that it will print all of the interestrate and not just round it.
I am not convinced that the issue is with BigDecimal. I think the issue may be with the NumberFormat class. As David mentioned, there is nothing in the JavaDoc that says that it supports anything but whole percents. It may support it, but the JavaDoc doesn't show it.
Please don't provide direct answers. Our goal at JavaRanch is to help people to learn, and to struggle through problems on their own. We are NotACodeMill, and we want people to DoYourOwnHomework. (Well, *their* own, but I want the link :)
Bhagat Singh Rawat
Joined: Apr 04, 2009
David Newton wrote:Please don't provide direct answers. Our goal at JavaRanch is to help people to learn, and to struggle through problems on their own. We are NotACodeMill, and we want people to DoYourOwnHomework. (Well, *their* own, but I want the link :)