Help wanting to limit output to 2 decimal places :O

im trying to make it so i only output over 2 decimal places.
here is my code. can someone tell me what to add? thank you mucho
package javaapplication2;
import java.util.*;
import cs1.Keyboard;
public class Main {
public static void main(String[] args) {
double Hours_Worked,
Hourly_Wage,
Total_Money;
final double COMMISSION = 3.59 * .1;
int noSoldFish;
String UserName;
System.out.println("Please enter the employee's name: ");
UserName = Keyboard.readString();
System.out.println("Please enter hours worked by employee: ");
Hours_Worked = Keyboard.readDouble();
System.out.println("Enter employee's hourly wage: $");
Hourly_Wage = Keyboard.readDouble();
System.out.println("Enter the number of fish sold by employee:");
noSoldFish = Keyboard.readInt();
Total_Money = Hours_Worked * Hourly_Wage + noSoldFish * COMMISSION;
System.out.println("\n===========================================" +
"\n Employee's Information" +
"\n===========================================" +
"\n" + UserName + " worked " + Hours_Worked + " hours this week" +
"\n" + UserName + " makes $" + Hourly_Wage + " per hour." +
"\nThe total salary and commission for "
+ UserName + " is $" + Total_Money);
System.exit(0);
}

read up on, or search the forum on NumberFormat and in particular the factory method NumberFormat.getCurrencyInstance(); This is what you need here.

Similar Messages

  • Help with limiting JOptionPane output to 2 decimal places

    I don't seem to be able to figure out how to specify 2 decimal points in my output to a JOptionPane. I know how to do this in a standard program with no gui interface but I have been unsuccessful in my attempts with JOptionPane. I have included my code below and any assistance at all would be appreciated.
    import javax.swing.JOptionPane;
    public class Vehicleanalysis2
    public static void main( String args[] )
    String januaryRepairs =
         JOptionPane.showInputDialog( "Enter January's repair costs:" );
    String februaryRepairs =
         JOptionPane.showInputDialog( "Enter February's repair costs:" );
    String marchRepairs =
         JOptionPane.showInputDialog( "Enter March's repair costs:" );
    String aprilRepairs =
         JOptionPane.showInputDialog( "Enter April's repair costs:" );
    String mayRepairs =
         JOptionPane.showInputDialog( "Enter May's repair costs:" );
    String juneRepairs =
         JOptionPane.showInputDialog( "Enter June's repair costs:" );
    String julyRepairs =
         JOptionPane.showInputDialog( "Enter July's repair costs:" );
    String augustRepairs =
         JOptionPane.showInputDialog( "Enter August's repair costs:" );
    String septemberRepairs =
         JOptionPane.showInputDialog( "Enter September's repair costs:" );
    String octoberRepairs =
         JOptionPane.showInputDialog( "Enter October's repair costs:" );
    String novemberRepairs =
         JOptionPane.showInputDialog( "Enter November's repair costs:" );
    String decemberRepairs =
         JOptionPane.showInputDialog( "Enter December's repair costs:" );
    double january = Double.parseDouble(januaryRepairs );
    double february = Double.parseDouble(februaryRepairs );
    double march = Double.parseDouble(marchRepairs );
    double april = Double.parseDouble(aprilRepairs );
    double may = Double.parseDouble(mayRepairs );
    double june = Double.parseDouble(juneRepairs );
    double july = Double.parseDouble(julyRepairs );
    double august = Double.parseDouble(augustRepairs );
    double september = Double.parseDouble(septemberRepairs );
    double october = Double.parseDouble(octoberRepairs );
    double november = Double.parseDouble(novemberRepairs );
    double december = Double.parseDouble(decemberRepairs );
    double annualrepaircost = january + february + march + april + may + june + july + august + september + october + november + december;
    double payment = annualrepaircost / 12;
    if (annualrepaircost <= 3600 )
         JOptionPane.showMessageDialog(null, "          Keep your car.\n          Your monthly repair\n          costs only average\n           out to be: " + payment + "\n          Your annual repair costs\n          this year\n were: " + annualrepaircost, " Recommendation", JOptionPane.PLAIN_MESSAGE );
    else
         JOptionPane.showMessageDialog(null, "          You should consider purchasing a new\n          car if you can get a payment\n          for less than: " + payment + "\n          Your annual repair costs\n          this year\n          were: " + annualrepaircost,
         " Recommendation: ", JOptionPane.PLAIN_MESSAGE );
    }

    Hi,
    try the following:
    double payment;
    JOptionPane.showMessageDialog(null, String.format("Payment: %.2f ", payment));
    /Mattias

  • How can I stabilize the DAQ output to four decimal places

    I have a daq 6009. I sent a optical signal. DAQ provides a output which varies in 3rd  decimal place. I done averaging all using a program which I'am attaching with this. So can you please help me in this regard 
    Attachments:
    data acquisition 2 (SubVI).vi ‏71 KB

    You need to find a DAQ with a lower Absolute Accuracy.
    Also, looking at the spec, you can get a better accuracy with a Differential measurement than you can with a RSE.  Apparently the RSE only works in the +-10V range.  By changing to a differential, you can get down to a +-1V range.  That will help your resolution a little bit.  Just wire the ground to the - terminals on the DAQ.
    Another issue could be noise in the system.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • ALV output is 2 decimal places, but prints as 3

    Hi,
    In my current ABAP program, the output is shown as 2 decimals, using the following domain:
    Data Type: QUAN
    No. Characters: 13
    Decimal Places: 2
    Output length: 17
    However, during unit testing, it was found that during printing, instead of printing it out as 2 decimals (ex. 12.00,) its printed out as 3 decimals (ex. 12.000.)
    The same thing can be noticed when using Print preview. It starts at the editable fields and continues onward to others.
    Why is this occurring and what can I do to fix this problem?
    Points will be rewarded and all help will be greatly appreciated.
    Thanks,
    John

    Hi
    Check once again the attributes of that Qty field in Dataelement and domain
    Because for all QUAN type fields it is always 3 DECIMAL places
    you are saying it is 2
    check it
    All the qty fields in SAP with data type QUAN uses/prints 3 decimals
    so check and  see
    like fields LFIMG.MENGE,FKIMG,KWMENG all fields with 3 decimals
    Reward points for useful Answers
    Regards
    Anji

  • Help!printing float values with two decimal places

    hi there java pips! im a newbie to this technology so forgive me for this really stupid question....i would like to perform mathematical operations on two float values....the problem is i want to print them in a standard format and that is i want them to be displayed with two decimal places (e.g 190.00, 12,72, 1,000.01) how can i do this?

    Try java.text.DecimalFormat
    NumberFormat nf = new DecimalFormat("0.00");
    System.out.println(nf.format(x));

  • Output to 2 decimal places

    Hi there,
    Got a small problem the output's are coming out like this 155.5 and i need them to come put like this 155.50
    <cfparam name="FORM.twin" type="string" default="1" />
    <cfquery name="twin" datasource="strand">
    SELECT *
    FROM hotel_rooms
    WHERE hotel_rooms.ID = 1</cfquery>
    <!---Twin CFIF--->
    <cfif form.twin gt "0" and form.nights eq "1">
    <cfset tprice = 1*#twin.price_night1#>
    <cfelseif form.twin gt "0" and form.nights eq "2">
    <cfset tprice1 = 2*#twin.price_night1#>
    <cfset tprice = #tprice1#*0.95>
    <cfelseif form.twin gt "0" and form.nights eq "3">
    <cfset tprice1 = 3*#twin.price_night1#>
    <cfset tprice = #tprice1#*0.90>
    <cfelseif form.twin gt "0" and form.nights gte "4" and form.nights lt "8">
    <cfset tprice1 = #form.nights#*#twin.price_night1#>
    <cfset tprice = #tprice1#*0.85>
    </cfif>
    <cfoutput>#tprice#</cfoutput>
    Any one any ideas.
    Thanks
    Jonathan Hemmings

    I have tried this:
    <cfoutput>#numberFormat(tprice,”-£____.__”)#</cfoutput>
    But i keep geting this error:
    The following information is meant for the website developer for debugging purposes.
    Error Occurred While Processing Request 
    Invalid construct: Either argument or name is missing. 
    When using named parameters to a function, each parameter must have a name.
    The CFML compiler was processing:
    An expression beginning with numberFormat, on line 269, column 57.This message is usually caused by a problem in the expressions structure.
    The body of a cfoutput tag beginning on line 269, column 47.
    The body of a cfoutput tag beginning on line 269, column 47.
    Am i using it wrong?
    Thanks
    Jonathan hemmings

  • Limiting decimal places

    is there a way to limit the number of decimal places that appear in an output?

    Yes, truncate it manually or by some input method limiter.
    If you are reading a spreadsheet file and outputting that to the console, then you can simply check the value of the string, and determine how many numbers come after the "." charactor. That will give you an index in the string.
    Using that index you can then simply create a new string including the whole number, decimal, and only those points that you want.
    You can also do the reverse and expand the decimals from, let's say 1 decimal (like 10.2) to a 2-digit decimal (like 10.20) by simply adding the needed places in the string after the last charactor.

  • How to take float precision to two decimal places?

    Hi, everybody:
    I'm a straight noob...first week in Java programming. Before you bash me for not checking FAQs and such, believe me, I have.
    I have tried BigDecimal movePointLeft, but I don't know how to construct it using proper syntax. I also tried currency and toString but I keep messing up my syntax somehow. Four hours into this and nothing is working.
    Here is the problem: I have a float. I want to format its output to two decimal places, trying to achieve in Java what C would produce as:
    printf("The amount you owe is $%.2f", fltAnyName);
    Any help would be appreciated.
    Thanks,
    Rob

    Sorry, guys. I have tried both recommendations and I can't get either to work. I'm getting a compile error pointing to the delineating period between the "out" and "printf" when I try the C-like code. I have 1.5, too. I know your advice is sound so I must be doing something wrong. Can you insert the code DecimalFormat code that will correct this problem where it needs to go? The packages below have been included becasue of all the different solutions I have attempted.
    import java.io.*;
    import java.math.*;
    import java.text.*;
    import java.lang.*;
    public class CoinCalculator2
         public static void main(String[] args) throws IOException
              String strQuartes, strDimes, strNickels, strPennies;
              int intQuartes, intDimes, intNickels, intPennies;
              float fltValue;
              BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));
              System.out.println("THE COIN CALCULATOR");
              System.out.println();
              System.out.print("Enter the number of quarters you have: ");
                   strQuartes = dataIn.readLine();
                   intQuartes = Integer.parseInt(strQuartes) * 25;
              System.out.print("Enter the number of dimes you have: ");
                   strDimes = dataIn.readLine();
                   intDimes = Integer.parseInt(strDimes) * 10;
              System.out.print("Enter the number of nickles you have: ");
                   strNickels = dataIn.readLine();
                   intNickels = Integer.parseInt(strNickels) * 5;
              System.out.print("Enter the number of pennies you have: ");
                   strPennies = dataIn.readLine();
                   intPennies = Integer.parseInt(strPennies);
              fltValue = (intQuartes + intDimes + intNickels + intPennies) / 100;
              System.out.println();
              System.out.println("The value of your coins is $" + fltValue);
              System.out.println();
    }

  • ToGB() decimal places

    Hi All,
    I have this piece of code which outputs the values to a html file.
    (get-mailboxdatabase)|foreach-object {
     $database= $_.name
     $accounts= (get-mailbox -database $_.name).count
     $size = (get-mailboxdatabase $_.name -status).databasesize.ToMB()/1024
         add-content $wfile "<tr>"
         add-content $wfile "<td align= 'center'>$database</td>"
         add-content $wfile "<td align= 'center'>$Accounts</td>"
         add-content $wfile "<td align= 'center'>$size</td>"   
    My issue I can't get the size to output to 2 decimal places it outputs 8 decimal places.
    If I use ToGB() instead of ToMB()/1024 I only get the whole number
    I have tried using {N0:02} but it doesn't help
    What am I doing wrong?
    TIA
    Andy

    How are you applying the format string?
    $size = '{0:N2}' -f ((get-mailboxdatabase $_.name -status).databasesize.ToMB()/1024)
    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

  • Save data with more than 6 decimal places in SAP MDM 5.5

    Hi there,
    I need some help concerning saving data with about 20 decimal places (e.g. 0,00452961328622164) in MDM. I declared the datatyp "REAL", there are only 6 decimal places possible.
    How can I save this Data? Maybe exponential function?
    Please help.
    Thank you
    Thomas Pfab

    currency takes you to 14 decimal places, if you want to have it as a little work around....you can always take out that symbol if it is annoying.(ohhh and decimal is multilingual too in currency, probably not a good hack!)
    or without even knwoing what your requirement is? try normalizing the value, How many more decimal places can you hit?
    One 100 1. "ten to the zero"
    tenth 10-1 0.1 "ten to the minus one"
    hundredth 10-2 0.01. "ten to the minus two"
    thousandth 10-3 0.001. "ten to the minus three"
    ten thousand 10-4 0.0001. "ten to the minus four"
    hundred thousandth 10-5 0.00001. "ten to the minus five"
    millionth 10-6 0.000001 "ten to the minus six"
    ten millionth 10-7 0.0000001. "ten to the minus seven"
    hundred millionth 10-8 0.00000001. "ten to the minus eight"
    billionth 10-9 0.000000001. "ten to the minus nine"
    ten billionth 10-10 0.0000000001. "ten to the minus ten"
    hundred billionth 10-11 0.00000000001. "ten to the minus eleven"
    trillionth 10-12 0.000000000001 "ten to the minus twelve"
    ten trillionth 10-13 0.0000000000001. "ten to the minus thirteen"
    hundred trillionth 10-14 0.00000000000001. "ten to the minus fourteen"
    and put that field label indicating the 10th power. Like "Accuracy in 10 POW -9"
    Just a wild guess.well thats how we usually show data in catalogues too!
    (or)
    separate the integer and decimal portions into two fields and store it in the repository.(split on ',')
    -Sudhir.

  • Round to two decimal places

    my cost per month textbox typically returns multiple decimal places, is it possible to limit it's output to two decimal places like real monetary calculations?
    calculatebutton.addEventListener(MouseEvent.CLICK, doMyCalculation);
    calculatebutton2.addEventListener(MouseEvent.CLICK, doMyCalculation2);
    costpermonth.restrict = ".0-9";
        var myAnswer : Number;
        myAnswer = Number(costofitem.text) - Number(amountsaved.text);
        amountneedtosave.text = String(myAnswer);
    function doMyCalculation2(e:MouseEvent):void
        var myAnswer2 : Number;
        myAnswer2 = Number(amountneedtosave.text) / Number(howmanymonths.text);
        costpermonth.text = String(myAnswer2);

    use the toFixed() method of numbers:
    amountneedtosave.text = myAnswer.toFixed(2);

  • Cannot Update Decimal Places in General Settings

    When I try to update the decimal points in the Administration > System Initialization > General Settings > Display path, SAP B1 gives me the following error:
    "Cannot update while another user is connected to the company."
    I am the only one on the system as "manager" with "Super User" and "Full Authorization"...
    The SAP B1 Guide titled "How to Make Initial Setting in Business One - US" says "you can change these settings at any time".
    QUESTION:  What might be stopping this change, and more importantly, how do I get around this error to be able to change the decimal points?
    Thanks all - Zal

    Hi Zal,
    I agree with you about the strange messaging used by SAP.
    But blocking the possibility to decrease the decimal places is extremely important.
    Suppose you have inserted a sales document with two items in this way:
    Item 1 ___Qty 1,234  ___Unit price 1,22  ___Line total  1,51
    Item 2 ___Qty  5,756 ___Unit price 3,15  ___Line total 18,13
    ____Document total 19,64
    Then, someone wants to change the number of decimal places of the quantity from 3 to 2.
    What happens would be:
    Item 1 ___Qty 1,23  ___Unit price 1,22  ___Line total  1,51
    Item 2 ___Qty  5,75 ___Unit price 3,15  ___Line total 18,13
    ____Document total 19,64
    If you try to do the calculations manually you will see that the results are not correct. In fact all the document would have to change in:
    Item 1 ___Qty 1,23  ___Unit price 1,22  ___Line total  1,50
    Item 2 ___Qty  5,75 ___Unit price 3,15  ___Line total 18,11
    ____Document total 19,61
    Also if the document total will show correct (in the case of rounding the second decimal position of item 2), the totals of any line is wrong. In fact there is no recalculation at all in SAP (and must not be done).
    Imagine such a modification over thousand of documents and all of the descendants (mainly if the have lead to printouts - as say confirmations - sent to customers or vendors).
    None of the economic figures will match.
    BR
    Antonio

  • Decimal places in doubles

    Hi,
    How do you limit the number of decimal places which are displayed by a double??
    Cheers
    David

    http://java.sun.com/docs/books/tutorial/i18n/format/index.html

  • Decimal Places in BOM

    Dear All
    How can i increase decimal places of components in BOM as it is taking only three decimal but i want to add upto 6 decimal. I mean i want to add component qty as 8.785642 in BOM. so how can i enter it

    Dear Ahmad,
    Go to transaction CUNI, Click on unit of measurement, select ur unit of measure(ex: M/L/KG etc) for which u want to maintain 6 decimals, In decimal places field maintain 6. come back and create BOM.
    test and come back
    sree

  • Changing the Decimal places in the currency

    Hi all
    we are using the currecy SAR. Decimal places was set to 4, now that they want to revert back to 2 decimal places. i understand that by doing so they would be inconsistencies in the data allready recorded. how to avoid that?
    is there any programmes / reports that would fix such inconsistencies?
    any OSS notes?
    thanks and regards
    gkk

    HI,
    You should NOT change the decimal places in a productive system.
    If you would do, the correction of the posted documents afterwards would be a remote consulting issue. Which you have to pay for SAP.
    You see, all posting you have done until now, would get displayed in a wrong way, and the new posting wouldn't compare to the others.
    Please check the note 137626 describes this.
    If you really need to change the decimals, you should create a new currency type, for example your current is SAR, and now you should create a SA2. Then you should enter new rations and exchange rates for it, and work with the new one.
    Also if you want to set the decimals to two digits from four, youshould not enter an entry in the OY04(TCURX).
    In this table you can only enter a value, that discriminate from 2 decimals. If there is no entry in the table, it means the currency has two decimals.
    Please assign points if it useful.
    Regards
    Ravinagh Boni

Maybe you are looking for

  • Using The Same Audio Files On Multiple Platforms

    When I import new audio into logic - often it will say that is creating wave forms for the display. Q: I notice that the audio files on disk do not show an altered modified date - so where are these wave form displays being saved - on the audio file

  • What's wrong with the anchor

    I would like to have the component in the following code on the top but it is always in the center, what is wrong with my anchor? Thanks for any help! private JPanel createParameterPanel(JLabel label, Component value) { JPanel panel = new JPanel(); G

  • Help Required for date display & mutating trigger

    Hai all.. I need clarification for 2 problems. Problem 1 Is there a possibility to display the values with a date range. I mean if there is no data for a particular date within the given range. it should display some null value. Eg. table name : samp

  • Strange bar position with waves- latency?

    Hi there, When I add waves tune to any audio track it causes the following strange annoying error : where ever i put the playhead and press play it start a a few beats before...so for eg if I go to bar 5 and press play it wil start near the end of ba

  • Should a clone copy mirror comp changes made to the parent region?

    Hi I've just made a clone copy of a region (song chorus) and I was hoping that if I made a change to the comp of the parent region that this would be mirrored in the copy. But that isn't happening. Is this something that should happen, and if so, can