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

how do you format currency in Java?

Status
Not open for further replies.

lhugh

MIS
May 21, 2000
115
CA
in my Access database the price data type is currency

i got the result set back and when i display the price is seen 12.0000

how do i show $12.00
 
//I assume you want to output from java
Code:
import java.util.Locale;
import java.text.DecimalFormat;
import java.text.NumberFormat;
class cal2
      {
       public static void main(String args[])
              {
         double d = 999999999999.999;
  String pattern = "###,###,###,###,###.00"; 
NumberFormat nf = NumberFormat.getNumberInstance(new Locale("en_US"));
DecimalFormat df = (DecimalFormat)nf;
  df.applyPattern(pattern);
String output2 = df.format(d);
System.out.println(pattern);
System.out.println(output2);

double yourNum =  12.0000;
df.applyPattern(pattern);
output2 = df.format(yourNum);
System.out.println("$"+output2);
              }
      }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top