Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formatting Numbers

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi,
I have tried to set the maximum number of fractions displayed to be 2 but when I run my program...the number displayed is only the integers....may I know what goes wrong?

Janet

Codes:

public static void category_menu(c1 a,c1 b,c1 c,c1 d,c1 e,c1 f,c1 g) throws IOException{

BufferedReader stdin = new BufferedReader
(new InputStreamReader(System.in));

String []table = {"Category", "Favourite", "Qty Prepared", "Qty Sold", "Selling Price($)"};
String option;
c1 p, q, r, s, t, u, v;

p = a;
q = b;
r = c;
s = d;
t = e;
u = f;
v = g;

NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(2);
nf.setMinimumIntegerDigits(1);

System.out.println("\n Cake [c1]"+p.getname()+"\t\t"+ p.display_prepared() + "\t "+ p.display_sold()+"\t\t "+ nf.format(p.price()) );

}
 
Why don't you just display it as currency?
Code:
NumberFormat nf = NumberFormat.getCurrencyInstance();
Forget about any other settings for the Formatter, the default currency instance for US JVMs is $X.00 . Should be just what yâÜI´eed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top