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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax question

Status
Not open for further replies.

scheenstra

Programmer
Feb 28, 2002
15
US
hi, i'm trying to use the command g.drawSring to post the value of a variable of type double to an applet screen. i'm wondering if anyone knows a way to tell it to only go two places after the decimal point. any help is greatly appreciated. Thanks
 
Ok, you need to use a numberformatter...

NumberFormat NF = NumberFormat.getInstance();

Now you have to customize NF...

NF.setMaximumFractionDigits (2);
NF.setMinimumFractionDigits (2);

Now you can use it as such...

g.drawString(NF.format(myNumber));

Remember to include java.text.*;

you can also use NumberFormat.getNumberInstance
NumberFormat.getCurrencyInstance
NumberFormat.getPercentInstance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top