Help Round decimal 2 palces

I have searched, but I cannot seem to find an answer to my question.
I am a student in into to programing and I am trying to figure out why my decimals will not round. I have tried everything I can find, but being new to java programing, I am sure I am making a syntatical error somewhere. My program works other than not displaying the decimal places the way I want, 200.00 not 200.0.
The following is my code, I have commented out each of the decimal formats I have tried.
import javax.swing.JOptionPane;
import java.text.DecimalFormat;
import java.text.NumberFormat;
public class CheckingAcct
     //int decimalPlaces = 2;
// Truncates the big decimal value.
//bd = bd.setScale(decimalPlaces, BigDecimal.ROUND_DOWN);
     //String string = bd.toString();
          //DecimalFormat df = new DecimalFormat ( "0.0#" );
               //DecimalFormat twoDigits = new DecimalFormat ( "0.0#" );
          //DecimalFormat decimalFormat = (DecimalFormat)numberFormat;
          //decimalFormat.applyPattern("0.0#");
     public static void main (String args[])
          String strBalance,
               strDeposit,
               strChecks;
          double balance = 200.00,
          deposit,
               lbcharge = 2.00,
               nsfcharge = 25.00,
               checks;
          //Display Starting Balance
          JOptionPane.showMessageDialog (null, "Your current balance is:$" + balance);
          //calculate balance
     strDeposit = JOptionPane.showInputDialog ("Please enter your deposit amount:$");
     deposit = Double.parseDouble (strDeposit);
     balance = deposit + balance;
     JOptionPane.showMessageDialog (null, "Your current balance after deposit is:$" + balance);
     strChecks = JOptionPane.showInputDialog ("Please enter the total amount of checks written:$");
     checks = Double.parseDouble (strChecks);
     balance = balance - checks;
     //Low Balance
     if (balance < 100.00)
          JOptionPane.showMessageDialog (null, "You have fallen below the minium required balance and you have been charged:$" + lbcharge);     
               balance = balance - lbcharge;
          else
               lbcharge = 0.00;
          //NSF Charge
     if (balance <= 0.00)
          JOptionPane.showMessageDialog (null, "You have a negative balance and you have been charged:$" + nsfcharge);     
               balance = (balance - nsfcharge);
          JOptionPane.showMessageDialog (null, "Your current balance is:$" + balance);     
          else
          JOptionPane.showMessageDialog (null, "Your balance is:$" + balance);
     System.exit (0);
}

I tend to use super class NumberFormat, because I can
never remember the jiggery-pokery of those patterns:
import java.text.*;
public class Example {
public static void main(String[] args) {
NumberFormat fmt = NumberFormat.getInstance();
fmt.setMinimumFractionDigits(2);
fmt.setMaximumFractionDigits(2);
System.out.println(fmt.format(200.0));
System.out.println(fmt.format(200.115));
System.out.println(fmt.format(200.125));
}Just be aware that NumberFormat/DecimalFormat uses
half-even rounding.This confirms another thought I had, that I must format each number I want to use. Thank you.

Similar Messages

  • Pleas help with rounding decimal field

    I have a totals field that is summing several fields. I wish to have this totals field provide a rounded sum. I've tried setting the trailing digits to 0 but it will not round up, only round down. I have a display pattern for the field of num{($z,zzz,zz9.99)} . Example 162.59 is displaying 162.00 in total field instead of 163.00. Is there something I'm missing or am I missunderstanding how a decimal field works?
    code in "calculate" event:
    var test=xfa.form.topmostSubform.personnel_page.person_1.salary_cost1.rawValue+
    xfa.form.topmostSubform.personnel_page.person_2.salary_cost2.rawValue+
    xfa.form.topmostSubform.personnel_page.person_3.salary_cost3.rawValue+
    xfa.form.topmostSubform.personnel_page.person_4.salary_cost4.rawValue+
    xfa.form.topmostSubform.personnel_page.person_5.salary_cost5.rawValue+
    xfa.form.topmostSubform.personnel_page.person_6.salary_cost6.rawValue+
    xfa.form.topmostSubform.personnel_page.person_7.salary_cost7.rawValue+
    xfa.form.topmostSubform.personnel_page.person_8.salary_cost8.rawValue+
    xfa.form.topmostSubform.personnel_page.person_9.salary_cost9.rawValue+
    xfa.form.topmostSubform.personnel_page.person_10.salary_cost10.rawValue;
    //this rounds the value upon exit of field
    var result = MATH.round(test.value);
    this.value = result;

    In FormCalc you have a function which do just what you are looking for..
    Ceil(162.59)
    Put it in a messageBox and see the output..
    form1.#subform[0].Button1::click - (FormCalc, client)
    $host.messageBox(Ceil(162.59));
    OR
    You can use the Ceil function of the MATH object in Java Script.
    form1.#subform[0].Button1::click - (JavaScript, client)
    xfa.host.messageBox("" + Math.ceil(162.59));
    Thanks
    Srini

  • Having some trouble rounding decimal place

    Hello all,
    I am having some issues rounding a decimal in my code. My program is running and doing what I would like otherwise. Here is what I have so far:
    public class MortCalc2
         public static void main(String [] args)
              //Declare and initialize three variables
              double numloanamt = 200000.00; //loan amount of 200k
              double numinterest = 0.0575;  //interest rate of 5.75%
              int numtermyrs = 30;  //term of 30 years
              int numtermmths = 360;  //term of 360 months
              double numwholeamt = 545000.00;  //loan amount + interest
              double numpayment = 0;  //monthly payment
              numpayment = numwholeamt/numtermmths;  //payment equals loan amount plus interest divided by the total term in months
              System.out.println("Your monthly payment is $" + numpayment);
    }I am getting the results I want with the calculation except they are coming out as 1513.888888888889. I would like to see 1513.89. Can someone point me in the right direction. Thank you in advance for any help you can provide.
    Thanks,
    Seawall

    Hi, sorry for the first post.
    this works okay.
    import java.math.*;
    public class MortCalc2
         public static void main(String [] args){
    are and initialize three variables
    double numloanamt = 200000.00; //loan amount of
    of 200k
    double numinterest = 0.0575;  //interest rate of
    of 5.75%
              int numtermyrs = 30;  //term of 30 years
              int numtermmths = 360;  //term of 360 months
    double numwholeamt = 545000.00;  //loan amount +
    + interest
              double numpayment = 0;  //monthly paymen
    numpayment = numwholeamt/numtermmths;  //payment
    t equals loan amount plus interest divided by the
    total term in months
    numpayment =
    Math.round(numpayment*100.0) / 100.0;
    System.out.println("Your monthly payment is $" +
    + numpayment);
    Thats right, use an Irish screwdriver (a hammer) instead of the correct solution as posted by djmd02 in repsonse #3.

  • Round Decimal value based on last digit

    Hi Experts,
    I'm trying to round the decimal value based on its last digit. If the last digit is >5 then add +1 to the digit before that and remove the last digit else just remove.
    ie.
    -59664.15000000005 should become -59664.15
    -21308625.00000002 should become -21308625
    -85234500.00000006 should become -85234500.0000001
    18288102.85714287 should become 18288102.8571429I tried with Round Function but it did not help,
    Pls assist.
    Thanks!

    Got it done just took the length and did the change.. sorry for this lame question.. should have tried before posting the question. Tx for your time...

  • Help Convert decimal to fraction

    Need covert decimal de piont float to fraction
    thats no easy for me.
    you like help me with my probleam
    I thank you very much
    sorry for me English
    i don't stand English
    My e-mail is [email protected]

    "jeans_mac" <[email protected]> wrote in
    message
    news:ecdb7a$k39$[email protected]..
    > Need covert decimal de piont float to fraction
    > thats no easy for me.
    > you like help me with my probleam
    > I thank you very much
    >
    > sorry for me English
    > i don't stand English
    http://www.lookmumimontheinternet.com/blog/?p=31

  • How to round decimal point to two places

    Hi all, I have been tasked with creating a custom "calculator" for a client that uses a specific equation. The client inputs data into two Input Text fields and the result shows up in a dynamic text field. Is there any way I can limit the number of decimal places to two? Here is my code (which works, except for the decimal issue):
    function onCalculate()
    one = Number(number_one);
    two = Number(number_two);
    result_1 = ((one / 4) * (65 / (1 - 0.25))) + ((two / 0.5) * (65 / (1 - 0.25)));
    Thanks in advance!!!!

    What will often be done is the result is first multiplied by 100, then rounded to an integer, then divided by 100.  So picking up from your last line where you calcvulate the result_1 value...
    result_1 = Math.round(result_1*100)/100;

  • Round decimal number to two places

    trying to round a decimal number to two places i.e. 1.98999 should round to 1.99.
    -tried using math.round but it only rounds to nearest integer
    -tried using decimalformat class but that converts to string, and cast wont allow me to convert from string back to double
    *is there a round method that allows you to specify decimal places?
    *or is there an easy method to cast a string back to a double?
    any advice is appreciated:)

    coynerm wrote:
    trying to round a decimal number to two places i.e. 1.98999 should round to 1.99.Agree.
    -tried using math.round but it only rounds to nearest integerI advise against rounding in most newbie situations. Usually it's the display of the variable you want to change.
    -tried using decimalformat class but that converts to string, and cast wont allow me to convert from string back to doubleOf course cast won't allow you to convert back. If you wanted to do that you'd use Double.parseDouble(stringVar); But we don't know why you are doing all this converting in the first place.
    *is there a round method that allows you to specify decimal places?
    *or is there an easy method to cast a string back to a double?Advice: Forgetting all this fooha with rounding, what in essence are you trying to achieve? Why all of this number manipulation in the first place? It will affect what should be the best answer.

  • FM to Round decimal place

    Hi Gurus,
    I want to reduce the number of decimal place by rounding off 2 decimal place.
    I am using 'HR_NZ_ROUNDING_DECIMALS' function module but its not working,
    kindly do the needful.
    Regards,
    Maithili

    Hi,
    Use Type cast method instead of finding FM.
    DATA : i type p decimals 4 VALUE '57846.5379'.
    DATA : j type p decimals 2.
    j = i.
    Write : / i.
    Write : / j.
    Regards,
    Velmurugan B

  • Help with decimal points

    hi,
    I'm trying to add commas, and 2 digit decimal point after a number. Can someone please help me with this small query.
    for example:
    63000 -> $63,000.00
    15000 -> $15,000.00
    2789164.15 -> $2,789,164.15Here is my code:
    select  '$'||ADJSTD_AMT
    from    finance.bud_lines
    where   fyr =2012Thanks in advance

    Rooney wrote:
    hi,
    I'm trying to add commas, and 2 digit decimal point after a number. Can someone please help me with this small query.
    for example:
    63000 -> $63,000.00
    15000 -> $15,000.00
    2789164.15 -> $2,789,164.15Here is my code:
    select  '$'||ADJSTD_AMT
    from    finance.bud_lines
    where   fyr =2012Thanks in advancewhen all else fails Read The Fine Manual
    http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions201.htm#SQLRF06130

  • Rounding decimal numbers in the planning book

    Hi,
    Is there any way to round up the decimal numbers shown in the forecast/inventory/DRP planning book of SPP ?
    Thanks and Regards
    Mitesh

    Hi Mitesh,
    Please go to SPRO:
    APO -> Supply Chain Planning -> SPP -> Settings for user interfaces -> Assign Key Figures
    Go to "Semantic Maintenance"
    Set "Decimal Places" Column to Zero for all key figures.
    Regards,
    Aapka Mukundan

  • Rounding Decimal

    Hi,
    I'm ABAP beginner, how can i round the decimal number to an integer in ABAP report or SAPScript??  Which FM should i use??
    Regards,
    Kit

    Hi
    Check this Sample
    DATA n TYPE p DECIMALS 2.
    DATA m TYPE p DECIMALS 2 VALUE '-5.55'.
    n = abs( m ).   WRITE:   'ABS:  ', n.
    n = sign( m ).  WRITE: / 'SIGN: ', n.
    n = ceil( m ).  WRITE: / 'CEIL: ', n.
    n = floor( m ). WRITE: / 'FLOOR:', n.
    n = trunc( m ). WRITE: / 'TRUNC:', n.
    n = frac( m ).  WRITE: / 'FRAC: ', n.
    ULINE.
    floating points
    DATA: result TYPE f,
          pi(10) TYPE c VALUE '3.14159265'.
    result = cos( pi ).
    WRITE result.
    Thanks,
    Praveen

  • Help - Rounding Double Value to 1d.p

    Hi there, I have a value which is going to be entered via keyboard it will be something like $309.99 or $856.87 and I need it to be rounded to the nearest 10C. E.g $309.99 would become $310.00 and $856.87 -> $856.90
    It doesn't even need to be at 1d.p but just round up to nearest 10C...
    Any help will be greatly appreciated..
    Thanks..

    I need it to be rounded to the nearest 10C.It's not quite clear what you mean by this. Should the number itself change to
    the nearest 0.1 of a dollar? Or should string used to display the number
    be made to resemble the examples you give ($310.00 etc)? The two
    things are very different, although both could be described as "rounding".
    public class RoundEg {
         public static void main(String[] args) {
              double d = 12.345;
                   // creates the string "$12.30"
              String s = String.format("$%.1f0", d);
              System.out.println(d + " --> " + s);
                   // changes d to 12.3
              d = Math.round(d * 10) / 10.0;
              System.out.println(d);
    }String.format() is 1.5, you might also have a look at the DecimalFormat class.

  • Round decimal

    Hi everyone, I wish you all a happy new year!
    When I use round and the result is between 0 and 1, the zero disappears:
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
    With the Partitioning, OLAP and Data Mining options
    SQL> select round(1/190*100,2) || '%' from dual;
    ROUN
    .53%Is there an easier way to get the zero back instead of doing something like this:
    select decode(substr(round(1/190*100,2),0,1),',', '0' || round(1/190*100,2) || '%', round(1/190*100,2) || '%') from dualThanks in advance.

    Two ways (you probably want the latter as the first is SQL*Plus specific)...
    SQL> col rnd format 990.99
    SQL> select round(1/190*100,2) as rnd from dual;
        RND
       0.53
    SQL> select to_char(round(1/190*100,2),'fm990.99')||'%' from dual;
    TO_CHAR(
    0.53%
    SQL>

  • CFCHART rounds decimal on mouseover

    I have a bar chart that is graphing percentages all of which
    contain decimals.
    See this link:
    http://beta.kirrmar.com/?pgid=142&prodid=2
    The chart is correct, but when mousing over a series, the
    value displayed is not the actual value, but a rounded value. I
    need it to display 2 deciaml places when moused over. Any idea how
    this can be controlled?

    http://www.coldfusionjedi.com/index.cfm/2009/3/6/Ask-a-Jedi-Showing-the-values-on-a-chart

  • Rounding decimal to 2 for any MessageTextInputBean which is mapped to EO

    Hi,
    I have an requirement where in the MessageTextInputBean user enters the values in the format (###.##############################) i am able to store the same in the back-end too but in the Page level after clicking on the save button the value should be stored in the back-end as the user entered but in the page level it should display in this format (###.##). Is it possible or any work-around to achieve this.
    Thanks.

    Suraj,
    If its just to display on the page, u can format the bean value to currency, setAttributeValue(CURRENCY_CODE,"USD");
    --Mukul                                                                                                                                                                                                                                                                                                                   

Maybe you are looking for

  • Error in creating triangle object

    I am getting an error message of " cannot resolve symbol"..when i tried to create an object for the triangle class.It points at the 'Triangle' class itself when the program is compiled. I just hope that I have imported the right package.Can somebody

  • How to adjust MTU? (xbox 360)

    how would i go about adjusting the mtu on my linksys router?Message Edited by SadPanda7 on 01-07-200712:24 PM

  • How do I change a file name of a photo

    I am new to the Mac and running Yoesomite. I wanted to know can I change the file name of a photo in iPhoto.  If not, then is the process to export the file to the desktop and then change the file name using cmd i.  I used to be able to do this in Wi

  • Standard error of mean for column/bar graphs

    Hi, Is it possible for me to have different standard errors in a column graph? (i.e. in a graph with 2 or more columns/bar to have their individual error bars drawn out?) So far I have only been able to have a single number for both columns in the gr

  • How can I change the use for iCal

    I currently use iCal so that my iPad, iPhone and iMac are all synch'g.  So far it has worked seemlessly until now at least! My iTunes account is setup under my wife's name so iCal is actually listed through her.  This has never been a problem but I j