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

Similar Messages

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

  • 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 only 2 decimal places

    Hi people, thank again in advance for your help.
    if i have a number with tons of decimal places behind it...and only wantto print on screen 2 (for instance when I am want $10.00 instead of $10.000000001) or somethign like that, what can i do?
    With Math.round() work? but i also want such that if the figure is zero....to be printed $0.00 and not $0.0.
    Can anybody helo?

    Thanx mark. but when i tried i get these errors.
    C:\WINDOWS\Desktop\BC201\assignment2\Savings.java:86: cannot resolve symbol
    symbol : class DecimalFormat
    location: class Savings
              DecimalFormat df = new DecimalFormat(".00");
    ^
    C:\WINDOWS\Desktop\BC201\assignment2\Savings.java:86: cannot resolve symbol
    symbol : class DecimalFormat
    location: class Savings
              DecimalFormat df = new DecimalFormat(".00");
    ^
    2 errors
    Tool completed with exit code 1

  • 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

  • PO print preview displays incorrect setting in decimal places

    Dear Experts
    Please help me on the following condition.
    I have a problem in print preview of a PO. It displays the incorrect setting for decimal place in currency.
    It shows USD 1.404,00 whereby the amount should be USD 1,404.00
    This only happens to a certain vendor that is doing PO for the first time from that country
    Example:
    I'm creating a PO for vendor 123. Vendor 123 is located in country A. No PO has been created for any
    vendor in country A before. When I saved my PO, in print preview, the decimal setting is not correct.
    But when I'm creating another PO, for vendor 234. Vendor 234 is located in country B. There have been
    several POs created for vendors in country B before. When I saved my PO, in print preview, the decimal
    setting is correct.
    Both vendor 123 and vendor 234 is using currency of USD.
    Is there any other setting with the vendor master in regard with the currency decimal setting for each
    country for the vendor? Or something that I've missed out?
    Diagnosis:
    I've checked with the user profiles->default-> decimal notation. It displays 1,234,567.89 correctly
    I've also run OY04, but the decimal setting is correct.
    Thank you
    Regards
    Syukri

    this has nothing to do with print preview, it is just basic country setting (OY01) how a quantity and value is written on a PO to a vendor is country xyz.
    German uses to comma to seperate decimals, while USA uses the point to seperate decimals
    this would be the German version 1.404,00, and this the US version:: 1,404.00
    so if an American sends a PO to a German vendor, then the document will show 1.404,00 so that the German can understand that he wants 1404. (and not 1000 times less)

  • Printing a double to accuracy of 2 decimal places

    Hi,
    I have a double value and I want to print it to an accuracy of 2 decimal places. Is there any way to do this. I tried using the DecimalFormat by
    doing the following
    String str = Double.toString(value);
    DecimalFormat dec = new DecimalFormat(str);
    dec.setMaximumFractionDigits(2);
    String res = dec.toString();But this doesn't seem to work. I am using java 1.4.
    Thanks

    You can use DecimalFormat but like this:
            double value = 1.345678d;
            System.out.println(value);
            DecimalFormat dec = new DecimalFormat("0.00");
            String result = dec.format(value);
            System.out.println(result);Or you can use a BigDecimal where you can specify the most appropriate rounding method:
            BigDecimal bd = new BigDecimal(value);
            bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
            System.out.println(bd.toString());HTH,
    Christian

  • Print Scale Percentage - Can the percentage go more than 2 decimal places??

    Hello All,
    Illustrator CS6
    I want to know if it is possible to get more than 2 decimal places in the Print Scale Percentage option box (as shown below)?
    It seems to round to 2 and I would like to get at least 3 for better accuracy.
    Any thoughts?
    Thanks
    Geoff

    Not that I know of. If you need it to be more exact, resize the artboard and scale the content. It's an arguable point, anyway, given how your printer will translate/ rasterize the stuff. Even if there were more digits, the result after the halfftoning might not at all be any different...
    Mylenium

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

  • 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

  • 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

  • Decimal places in Query generator

    Hi All,
    I am observing a weird behavior in Query generator's execution of a simple sql query. the query is :
    Select 0.002834
    now, in the general settings - display - amounts , I put the decimal value as 4 or 6,  then only it prints 0.0028 or 0.002834.
    else it prints 0.00 (if the decimal place is 2). it should ideally have nothing to do with the display of amount. any idea?
    (the effect is shown only after you change the decimal display, update it and close and reopen the SAP application.
    Thanks,
    Binita
    Edited by: Binita  Joshi on Apr 12, 2010 4:03 PM

    Hello Binita,
    >I have tried converting it to numeric(19,4) and numeric(19,6) but still the result was same.
    Check your decimal places settings in
    \Administration\System Initialization\General Settings\Display tab
    Check the following values:
    - Units (For meaurement)
    - Decimals in Query
    Now let' s say,
    - Unit set to 6 decimal places
    - Decimals in Query set to 2
    run the following query in query generator:
    select cast(0.000245 as decimal(19,6))
    result will be
    0.00
    run the same query as FMS on item master data in any measurement field (lenght)
    select cast(0.000245 as decimal(19,6))
    result will be
    0.000245
    Now set the - Decimals in Query set to 6 on  \Administration\System Initialization\General Settings\Display tab
    run the following query in query generator:
    select cast(0.000245 as decimal(19,6))
    result will be
    0.000245
    This is a normal habit of SAP B1 rounding engine / displaying engine.
    Regards
    J.

  • Decimal places on forms

    The decimal places in General Settings>Display is set to 6 for Amounts and Prices.  They would like only 2 decimal places to acutally print on the SO and AR Invoice.  How can we do this?

    Hi Kathy,
    You can add another formular field with round(Field_XXX,2) to display only two decimal places for any fields. Then hide the long decimal field.
    Thanks,
    Gordon

  • Formatting currencies and decimal places

    I'm currently using NumberFormat.getCurrencyInstance() to format numbers as currency. However, one problem I'm having is that I'd like values with no cents to be formatted with no decimal places, and any values with cents to be formatted with the usual 2 decimal places. For example:
    17 would be formatted as $17
    17.45 would be formatted as $17.45
    17.4 would be formatted as $17.40
    The last one is the tricky part--I've tried formatter.setMinimumFractionDigits(0), and this works great for the first two cases. But for the last case, the number gets formatted as $17.4.
    Basically my problem is I want a number to be formatted with zero or two decimal places and nothing in between. Is there an easy way to do this?
    Thanks in advance.

    Otherwise you are likely to find that you are getting .00 due to errors from previous calculations. You are right. Adjusted it to Locale aware
    import java.text.FieldPosition;
    import java.text.NumberFormat;
    import java.text.ParseException;
    import java.text.ParsePosition;
    import java.util.Locale;
    public class SpecialCurrencyFormat extends NumberFormat {
        private static final long serialVersionUID = 1L;
        private final NumberFormat noDecimals;
        private final NumberFormat decimals;
        private final double maxDifference;
        private final double factor;
        public SpecialCurrencyFormat() {
         this(Locale.getDefault());
        public SpecialCurrencyFormat(Locale locale) {
         decimals = NumberFormat.getCurrencyInstance(locale);
         noDecimals = NumberFormat.getCurrencyInstance(locale);
         noDecimals.setMaximumFractionDigits(0);
         maxDifference = Math.pow(10, -decimals.getMaximumFractionDigits()) * .5;
         factor = Math.pow(10, decimals.getMaximumFractionDigits());
        @Override
        public StringBuffer format(double number, StringBuffer toAppendTo,
             FieldPosition pos) {
         double adjustedValue = (Math.round(number * factor)) / factor;
         if ((Math.abs(number - Math.round(number)) < maxDifference)) {
             return noDecimals.format(adjustedValue, toAppendTo, pos);
         } else {
             return decimals.format(adjustedValue, toAppendTo, pos);
        @Override
        public StringBuffer format(long number, StringBuffer toAppendTo,
             FieldPosition pos) {
         return noDecimals.format(number, toAppendTo, pos);
        @Override
        public Number parse(String source, ParsePosition parsePosition) {
         return decimals.parse(source, parsePosition);
        public static void main(String[] args) {
         NumberFormat nf = new SpecialCurrencyFormat(Locale.US);
         double[] values = { 10000, 1000, 100, 10, 1, 10.1, 10.01, 10.001,
              10.002, 10.003, 10.004, 10.005, 10.006, 10.007, 10.008, 10.009,
              10.010 };
         for (double value : values) {
             print(nf, value);
        private static void print(NumberFormat nf, double number) {
         String formatted = nf.format(number);
         try {
             System.out.println(number + "\tas " + formatted + "\tand back "
                  + nf.parse(formatted));
         } catch (ParseException e) {
             e.printStackTrace();
    }The value adjustedValue is needed since NumberFormat doesn't seem to round the value. It just breaks.
    Piet

  • Rounding a quantity field to one decimal place. PLEASE URGENT

    I have a quantity field with three decimal places. I have to print this field with only one decimal place. This is in a smartform.
    suppose: qty = 45.678
    I want it to be printed as 45.7
    Thanks in advance.

    Hi Riki,
    I think you can use Function Module ROUND to round off the value...
    REPORT ZTEST_SHAIL4 .
    data: out type p decimals 1,
    inp type f.
    inp = '45.678'.
    CALL FUNCTION 'ROUND'
    EXPORTING
    DECIMALS =
    input = inp
    SIGN = ' '
    IMPORTING
    OUTPUT = out
    EXCEPTIONS
    INPUT_INVALID = 1
    OVERFLOW = 2
    TYPE_INVALID = 3
    OTHERS = 4
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    Now use the variable 'out' to display the rounded off value...
    Regards,
    SP.

Maybe you are looking for

  • Syncing my iPhone 3gs to my new HP laptop

    I recently got a new laptop which is an HP, and I didn't ever try to sync my iPhone 3GS to it because I thought the empty library on the computer would overide my library and erase my phone's data. I was able to jump the music from my old laptop onto

  • My I message is not working, since IOS 8.3 update.

    My messages is not working properly, since IOS 8.3 update. Message are left hanging as undelivered. When I tap on "try again" nothing happens. Even messages to known contacts with I phones, appear in green and does not get delivered anyway. I have re

  • Google Maps Widget Not Showing Marker

    I've added the Google Maps Widget to my page, but the marker doesn't show in the map:  http://www.lessue.com/JUNK2GO/les-sue_contact.htm.  The map is positioned correctly but a marker is needed.  addMarker() should be at least be showing "We are Here

  • Feature request...pkg.tar.bz2 support?

    As an arch lover who recently downgraded to a dial up connection, I was wondering if it might be prudent to have pacman support bz2 packages so that especially large packages might be more swiftly downloaded. Moreover, looking in the long term, an ev

  • Is there a way to use the drop zones as a preview area for highlighted video

    I'm making a fairly simple dvd menu, using the centre stage theme  Title Page and I was wondering if there was anway to use the drop zone as a preview area for the highlighted video. Thanks!