There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
bios black screen blue screen blue screen of death boot computer connection crash css dell display driver drivers email error firefox firefox 3 hard drive internet internet explorer itunes laptop lcd linux malware monitor network networking outlook outlook 2003 outlook express password printer problem problems ram router security slow software sound sprtcmd.exe trojan usb video virus vista windows windows xp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
question concerning currency output?


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
RedWizard's Avatar
Member with 48 posts.
 
Join Date: Jan 2007
03-Mar-2007, 08:51 PM #1
question concerning currency output?
Recently I made a little tax calculation proggy.

Unfortunately; I am unable to discover how to format the results into currency.

My code looks like this

import javax.swing.*; //imports java swing to implement msgbox
public class GetTax //creates class GetTax
{
public static void main (String[] args) //beginning of code
{
String result, output;
double tax, rate;

result = JOptionPane.showInputDialog("Enter the amount of the bill:");
//input msgbox. input for amount of bill.

tax = Double.parseDouble(result);
rate = .06 * tax; //calculate .06 * defined input

//display the calculated results
output = "The sales tax for " + tax + " is " + rate;
JOptionPane.showMessageDialog(null, output, "Tax Calculator",
JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}




If anyone can offer suggestions as to how to format the output into currency i'd be very interested.

thanks
RedWizard's Avatar
Member with 48 posts.
 
Join Date: Jan 2007
03-Mar-2007, 08:57 PM #2
i'm using java; of course.

fyi
Chicon's Avatar
Computer Specs
Distinguished Member with 6,681 posts.
 
Join Date: Jul 2004
Location: 50° 34' 07.13" N - 04° 10' 23.
Experience: Second socks retriever
04-Mar-2007, 07:01 AM #3
Here's a solution :

Code:
NumberFormat nf = NumberFormat.getPercentInstance(Locale.getDefault()); // add this line to your code
....
output = "The sales tax for " + tax + " is " + nf.format(rate);        // adapt the result to display
...
Edit :

Also, if you want to get the default currency of your computer, just add this command :

String currency = Currency.getInstance(Locale.getDefault()).getCurrencyCode();

Normally, the string currency will normally contain EUR if your computer is configured according to the settings of your country.


Last edited by Chicon : 04-Mar-2007 07:11 AM.
RedWizard's Avatar
Member with 48 posts.
 
Join Date: Jan 2007
04-Mar-2007, 01:12 PM #4
chicon you're the man.

i hereby label you my official java helper

=x

thanks buddy
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 08:57 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.