Printing to two decimal places on the screen

Hi everyone...
I am using mysql as my DB...my field is declared there as decimal(8,2) means to 2 decimal place..when i am getting the result i also need to print to 2 decimal place...
so when i do(rs.getDouble("Price")) it is not printing as two decimal place...how do i get it to print to 2 decimal place...
Thanx a lotttttt

javax.text.DecimalFormat dfrm t=new java.text.DecimalFormat("#0.00");
//or another format see API doc for DecimalFOrmat
String result = dfrm.format(rs.getDouble("Price"));

Similar Messages

  • JPY value shifted to two decimal places in the EBAN  Table

    Hi folks,
    We are in SRM 4 SP13 and ECC 4.6 C  Classis Scenario.
    When a  SC is raised in JPY currency  ,the  total value is carried to  PR in the backend correctly.
    But in the EBAN  table  under the PRIES field ,the total  value is shown as  the 1/100 of the value.
    This is happening only with JPY currency( no decimal values).
    So the report based on this total value is not showing the correct  value of the SC.
    Please let me know if I need to implement any changes or note to be applied.
    Thanks in advance,
    Rajesh

    Hi Masa ,
    Thanks for the reply.
    I displayed the PR  through ME53N in the backend. It displays the correct value in the valuation field.
    But whencheck the same in the EBAN table under PRIES it is showing 1/100 fo the value.
    We have a customised report which picks up this value from this table.
    Regards,
    Rajesh

  • Suppressing decimal places in the screen fields

    Hello All,
    I need to display a quantity fields which is referring to the domain MENGE(10+3)
    While displaying, it appears as 1234567890.000
    here how to suppresss the zero's.
    Screen field is got from program(not dictionary)
    can you help me out.
    Regrds,
    Subramanian.

    Hi,
    Try the following..
    in the attributes for the menge field give the Reference field (down below the attributes screen)...
    Also Check the check box Right justified..
    Thanks,
    Naren

  • Printing exactly 2 decimal places

    I'm trying to print my double type variables to exactly 2 places. but numbers such as 3.00 and 124.00 keep printing as 3.0 and 124.0. Is there an easy way to force the printing to two decimal places on a primitive double type value without having to cast it to a Double object and playing around with NumberFormat and all that entails?
    thanks much,
    jh

    darelln has exactly the right answer, except that you must do the thing you don't want to do. If it were me, I'd go with his example. It's less work and much cleaner.
    import java.text.*;
    public class DoubleTest {
    static double[] numbers = {3000, 124.12, 123.122, 3.0, 124.0, 10.2, 12.14, 1234.55};
    static final NumberFormat f = new DecimalFormat("#.00");
        public static void main(String [] args) {
            System.out.println("Goofy way!\n");
            for (int i=0 ; i<numbers.length ; i++) {
                printD(numbers);
    System.out.println("\nRight way!\n");
    for (int i=0 ; i<numbers.length ; i++) {
    System.out.println(f.format(numbers[i]));
    static void printD(double dbl) {
    if (dbl % 10 == 0) {
    System.out.println(dbl + "0");
    } else {
    String sdbl = "" + dbl;
    String predot = sdbl.substring(0, sdbl.indexOf("."));
    String atdot = sdbl.substring(sdbl.indexOf("."), sdbl.length());
    String postdot = sdbl.substring(sdbl.indexOf(".") + 1, sdbl.length());
    if (postdot.length() == 2) {
    System.out.println(sdbl);
    } else if (postdot.length() < 2) {
    System.out.println(predot + "." + postdot.substring(0,1) + "0");
    } else {
    System.out.println(predot + "." + postdot.substring(0,2));
    java DoubleTest
    Goofy way!
    3000.00
    124.12
    123.12
    3.00
    124.00
    10.20
    12.14
    1234.55
    Right way!
    3000.00
    124.12
    123.12
    3.00
    124.00
    10.20
    12.14
    1234.55
    and the results are identical!

  • Printing to 2 decimal places

    i have my database in mysql and my field total is declared as decimal to 2 decimal place.....how to i get it to print to two decimal place in my JSP page...i have declared the variable as double but when it is printing it is printing to one decimal place only...please help

    don't declare ur column as decimal in MySQL . Declare as decimal(3,2);
    thanx,
    Samir

  • How to add 2 decimal places if the number is whole number(Integer)

    Hi Gurus- I had a requirement to add the zeros for two decimal places even the number is an whole number.
    Example: I had a column which i gave the datatype as Number(8,2) .While Inserting from the flat file to the custom table column,i am rounding it to 2 decimal places.But if its the whole number i want that also to be rounded to 2 decimal places.
    1) 3456.89675 It's getting inserted as 3456.89
    2) 123 It's getting inserted as 123 (Instead i want this to be inserted as 123.00)
    3) 123.50000 It's getting inserted as 123.5 (Instead i want this to be inserted as 123.50)
    Can you please let me know how can i achieve it to insert any number(decimal or whole number) from the flat file as 2 decimal places in the custom table column.
    Thanks in advance.

    Please do not post duplicates -- To update the date for the first of the month

  • Print Doubles to two decimal places?

    When I do calculations on my double numbers and then print them on screen I get a string of digits after the decimal point. Can anyone give me the code as to how I use the DecimalFormat class to make these digits print to 2 decimal places. I am sure it is very simple line or two of code but I am unsure how.
    Thanks

    double number = 123456.789;
    DecimalFormat df = new DecimalFormat("#,##0.00");
    System.out.println(df.format(number));
    DesQuite

  • 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));

  • Reduce the field value from three decimal places to two decimal places

    hi experts,
    plz help me with this
    actually i have to display the  value of the field MENGE in the list with two decimal places.
    but when i go and see the field menge in the table mseg it is having three decimal places.
    so could u plz suggest me how to solve this.
    regards
    siri

    Please try using the DEIMALS extension of the WRITE statement.
    data: menge type menge_D value '1234'.
    write:/ menge decimals 2.
    Regards,
    RIch HEilman

  • Double value truncated to two decimal places without rounding the value.

    I want to truncate double value to two decimal places without doing the rounding of the value.
    Is there any method which can directly do the truncation.

    There's many ways to achieve this such as using
    BigDecimal's setScale method or type-casting. This is
    the way I like to do it:double d = -5.239;
    d = d > 0 ? Math.floor(d * 100) / 100.0 : Math.ceil(d
    * 100) / 100.0;
    Your division by 100 may cause an rounding error, because there are numbers which no finite binary representation. That's splitting hairs! I know ;-)

  • Printing two decimal places from BigDecimal values

    I am using BigDecimal to represent money values. My output needs to line up so that (with a non-proportional font) the decimal point and the two decimal places are in the same columns for each line. But when the dollar value has zero cents, or has a number of cents that is divisible by ten, it drops the trailing zeroes, and drops the decimal point if the decimal places are both zeroes. For example, I want to see "25.00" instead of "25" and "25.50" instead of "25.5". It doesn't seem to make any difference if I set the scale to 2. (I have resorted to getting the toString() of the BigDecimal and hacking the string before I display it, but surely there must be an easier way?)
          BigDecimal aaa = new BigDecimal("25");
          BigDecimal bbb = new BigDecimal("25.0");
          BigDecimal ccc = new BigDecimal("25.00");
          BigDecimal ddd = new BigDecimal("25.5");
          BigDecimal eee = new BigDecimal("25.50");
          BigDecimal fff = new BigDecimal("25.75");
          aaa.setScale(2);
          bbb.setScale(2);
          ccc.setScale(2);
          ddd.setScale(2);
          eee.setScale(2);
          fff.setScale(2);
          System.out.println("SCALE SET TO 2: ");
          System.out.println("aaa = " + aaa);
          System.out.println("bbb = " + bbb);
          System.out.println("ccc = " + ccc);
          System.out.println("ddd = " + ddd);
          System.out.println("eee = " + eee);
          System.out.println("fff = " + fff);produces this output:
    SCALE SET TO 2:
    aaa = 25
    bbb = 25.0
    ccc = 25.00
    ddd = 25.5
    eee = 25.50
    fff = 25.75Thanks,
    Martin

    Thankyou Dr. Clap. This solved my problem - I added an LHS to the setScale statements:
          aaa = aaa.setScale(2);
          bbb = bbb.setScale(2);
          ccc = ccc.setScale(2);
          ddd = ddd.setScale(2);
          eee = eee.setScale(2);
          System.out.println("SCALE SET TO 2: ");
          System.out.println("aaa = " + aaa);
          System.out.println("bbb = " + bbb);
          System.out.println("ccc = " + ccc);
          System.out.println("ddd = " + ddd);
          System.out.println("eee = " + eee);produced:
    SCALE SET TO 2:
    aaa = 25.00
    bbb = 25.00
    ccc = 25.00
    ddd = 25.50
    eee = 25.50

  • Convert amount with four decimal places to amount with two decimal places

    Hi,
    for specific reasons we have set the prices to four decimal places. However, in an invoice the staff needs to see all prices with two decimal places. Therefore I have created new user-defined fields which should show the rounded values However, I have not yet found the right formatted search that outputs the value with two decimal places including currency symbol.
    The statement 
    SELECT $[$38.20.NUMBER]
    outputs the value with two decimal places which is fine, but it does not contain the currency.
    The statement
    SELECT $[$38.20.0]
    outputs both value and currency, but the value still has four decimal places as the original price.
    And the statement
    SELECT CAST($[$38.20.NUMBER] AS VARCHAR(20)) + $[$38.20.CURRENCY]
    outputs a value with even six decimal places.
    Did anyone already have the same problem???
    Or does anyone have any idea???
    Thanks and regards
    Corinna

    Hi again,
    the value should be displayed in a user-defined field of the screen.
    The result of the query
    SELECT $[$38.20.NUMBER]
    has already two decimal places, so that I do not need a round here. But the currency is missing.
    When I add the round function to the query
    SELECT $[$38.20.0]
    it does unfortunatly result in an error.
    Any ideas????
    Thanks so much in advance!

  • Is it possible to convert a float to two decimal places

    Can anyone help me to convert a float to two decimal places
    float f=16;
    System.out.println(f);
    It will print 16.0
    But I want to get printed as 16.00

    "convert" no, as no conversion is needed, obviously. Format the output, yes. Read the API for String and its printf method.

  • 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();
    }

  • Trunc percentage two decimal places

    I have a report that has the option of dispalying pdf or excel. I have the pdf version working fine but i am having a little trouble on the excel version. I have a grand total and department total. Basically I need help formating two decimal places. Both dept_total and grand_total are numbers that both display. I have another column that displays what percent of the total is from each dept.It currently returns a number such as 10.23383547957459973 which i need to display as 10.23 How can i incorporate the trunc function into this code?
    ...to_char((dept_total/grand_total) *100)
    The query looks similar to this.
    select
    to_char(a._grand_total)
    ,to_char(a.dept_total)
    ,to_char((dept_total/grand_total) *100)
    from(
    select sum(xxxx) grand_total,
    sum(xxxx) dept_total
    from table)a

    Hi,
    Since you're calling TO_CHAR anyway, you can add a 2nd argument, specifying two decimal places:
    select
         a._grand_total
    ,     a.dept_total
    ,     to_char ((dept_total/grand_total) *100,       '999999999.99')     AS pct
    from     (
             select  sum (xxxx) grand_total,
                      sum (xxxx) dept_total     -- Why have two copies of the same value?
             from    table
         )a If you're not using a 2nd argument, why use TO_CHAR at all in this query?
    This will round the value, not truncate it. That is, if the value is 10.23<b>5</b>83547957459973, it would display '10.2<b>4</b>', not '10.2<b>3</b>'. If you always want to round toward 0 (rather than to the nearest multiple of .01), then use TRUNC.

Maybe you are looking for

  • Get info window displays generic jpeg icon

    For some reason, in Finder and the top of the Get Info window, the icons are showing as the generic jpeg icons instead of a thumbnail preview. Any ideas?

  • Dynamic service chains

    Hi, [new to jcaps] I have a sequence of services, say serviceA -> serviceB -> serviceC. I wish to add another service to that sequence, but I want to dynamically determine which JCD is called as ServiceD. The interface contract for all potential serv

  • Recommend me a good wireless card

    I currently use a DWL-122 (prism2_usb) adapter for wlan and I am getting tired of the driver problems: ndiswrapper (any version) causes a kernel panic and wlan-ng26 does not support WPA (i tried, and it's not supported by the WPA supplicant either).

  • Short dump while loading from ods1 to ods2

    hi, When iam loading from ODS1 to ODS2 geting shortdump.I generated ODS1 as datasource and iam loading the data.Can i able to delete the generated datasource from datamarts. bye GK

  • Approve Request App on Fiori Wave2 - Error

    Hi, We are trying to use the Approve Request App on Fiori Wave2.A dynamic tile has been created. While trying to launch the app from the Approver id we get a popup saying Failure-Unable to launch App. Steps mentioned in the Approve Request app on SCN