0

I have problem formating this code to displey 2 decimal points

public String toString() 
      {
         return super.toString() + "\n\tYear Level:\t" + getYearLevel() + "\n\tTuition:\t$" + "%1$.2f",calcTuition();
      
      }

calcTuition is type double

how can I do this?

Thanks

2
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by Ezzaral
Featured Replies
  • 1
    Ezzaral 2,714   5 Years Ago

    You really only need the "%.2f" part. You can read all about the formatting options here: [url]http://docs.oracle.com/javase/6/docs/api/java/util/Formatter.html#syntax[/url] Read More

0
public String toString() 
      {
         return super.toString() + "\n\tResearch Area:\t" + getResearchArea() + "\n\tTuition:\t$" + String.format("%.2g%n", calcTuition());
      
      }

like that I get number like ; $7.2e+03
dont get it?

0

got it :D

But can some tell me where can I find more info about it?

public String toString() 
      {
         return super.toString() + "\n\tYear Level:\t" + getYearLevel() + "\n\tTuition:\t$" + String.format("%.2f%n", calcTuition());
      
      }

Edited by mehnihma: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.