Float / Double Decimal Display

How do you get a float or double to display a certain amount of decimal places?
For example, dealing with money, to have it be displayed as $1.30 instead of $1.3

Use NumberFormat class!
A simple example:
NumberFormat currency = NumberFormat.getNumberInstance();
currency.setMinimumFractionDigits(2);
currency.setMaximumFractionDigits(2);
System.out.println(currency.format(AnyValue));

Similar Messages

  • Floating Point Decimal Displays

    Hello,
       OK - now for a wierd one.  I have a Z-attribute of 0MATERIAL that is FLTP format.  When I go to SE16 and look at /BI0/PMATERIAL I can't see that field because it is FLTP.  Is there any way that I can see it in BW, or do I have to go down to the DB level?
       Thanks - will award points for helpful answer...
    Dave Knudson

    Hi Dave,
    It doesn't matter if one of the attribute of ZMATERIAL is of FLTP format. You should be able to select that field for field selection as well as in the Output.
    by default the field selection may not show all the attributes. GOTO >settings>Field for selection and give the filed name.
    While the output is displayed by default the output result width is 250 characters change the output width to max 1023 it would display all the characters.
    Assign points if useful.
    Thanks & Regards,
    Namrata

  • Setting precision value of float/double

    Hi,
    I am retrieving data from database in to a float/double datatye. when i display the value it is showing the decimal of 4 to 5.(ex:4325.65785) but i want to display it as (ex:4235.65).
    Thanks
    Gopi

    import java.text.DecimalFormat;
    public class FormatTest
         public static void main(String[] args)
              DecimalFormat df = new DecimalFormat("##0.00");
              double d = 123456.2345678;
              System.out.println("Formatted: " + df.format(d));

  • Float/double implementation

    I am writing an application in J2ME and badly need a float/double data type, which J2ME does not have. I was wondering if anybody had some good ideas on how to implement a float/double data type using only ints.
    Thanks.
    AnjuM

    Use 2 longs, one for the 1's and one for the deciamal part. if the decimal part is over the max number you want to represent in decimal then subtract max from it and add 1 to the 1's side.
    If I wanted to show 9 decimal places, then anything past 999,999,999 should have 1,000,000,000 subtracted from it and 1 added to the left side.

  • Problem with decimal display

    Hi everybody,
    when I make reports by report painter (GRR1), I can choose decimal display (for example: 1,234 or 1.234). But when I make reports by drilldown report (KE84), SAP use default point instead of comma. I can't change it. How to choose decimal display is comma (1,234) in drilldown report?
    Thanks

    Hi Sangram,
    I changed setting according to your instruction. But It's useless. When I execute report, SAP still display $1.745.600.
    Edited by: Phu Quoc Si on Dec 22, 2011 8:42 AM

  • Float/double data types

    I use
    public void setId(float id) {this.id = id;}
    and
    setId(new Float(nodeNextTop.getChildNodes().item(0).getNodeValue()).floatValue());
    in my java files to get the value of a float which I want to display using
    <display:column align="center" sortable="true" nowrap="true" property="id" title="<%=id_%>" class="webText" />
    in my jsp file
    but it is displayed in true E format, ie, 1.123456789101112E15, I want to display the number as is, without the E, and it's beaten me, pls help.
    btw, double does the same

    top job, I'm learning something new each day, big thnx for the help

  • Floating point decimal

    Hi,
    How to get standard floating decimal number out of:
    double a = 0.0;
    double ans = (double)a+1.0/(397+658);
    the answer woulld be 9.478672985781991E-4. how to get say, 0.00094787 as double?
    please help.
    many thanks

    Or use Java 5's Formatter class (or one of its related methods), or BigDecimal class (Or some combination of any of the above.)

  • Float - double == loss of accuracy?  why?

    The following test fails:
    public void testFloat() {
            float number = 46702.45F;
            Float numberAsFloat = new Float(number);
            double numberAsDouble = numberAsFloat.doubleValue();
            System.out.println(numberAsDouble);
            assertTrue(46702.45 == numberAsDouble);
    }I probably just don't understand floating point data types or something, but I was very surprised that this test fails. If someone could enlighten me on WHY this fails, I would really appreciate it. For what it's worth, the value printed out for numberAsDouble was 46702.44921875 which I find entirely unexpected considering I am going from a lower precision data type (float) to a higher precision data type (double).

    Remember: the floating point representations (float and double) store binary values. Not decimal. The decimal values are parsed by the compiler and turned into floats and doubles in binary.
    The said binary values are approximations to the decimal values. Sometimes the binary and the decimal values coincide, but some times they don't.
    Floats have less precision than doubles.
    The binary string that represents that number, in a float, will be interpreted differently in a double, because the double has those additional bits of precision.
    Consider this code:
        double nd = 46702.45d;
        float nf = 46702.45F;
        long ndl = Double.doubleToLongBits(nd);
        long nfl = Float.floatToIntBits(nf);
        long nfl2 = Double.doubleToLongBits(nf);
        System.out.println(Long.toBinaryString(ndl));
        System.out.println(Long.toBinaryString(nfl));
        System.out.println(Long.toBinaryString(nfl2));It prints this:
    100000011100110110011011100111001100110011001100110011001100110
    1000111001101100110111001110011
    100000011100110110011011100111001100000000000000000000000000000
    // now I add spaces to line up the various segments
    // sign   exponent  mantissa
         1 00000011100  110110011011100111001100110011001100110011001100110
         1    00011100  1101100110111001110011
         1 00000011100  110110011011100111001100000000000000000000000000000Look at that string of "0011"'s on the version of the number created as a double.
    Compare it to the 0's in the version that was created as a float and used as a double.

  • Float & double variables

    I need to calculate money values, and was wondering how you get the float or double value to return only two characters after the decimal point?!

    Using float or double is not the best way for
    handling money. You may loose some....
    What about using BigDecimal?
    http://www.javaworld.com/javaworld/jw-06-2001/jw-0601-
    cents.htmlActually, he's probably converting money types (like dollars to pounds or whatever), and the teacher probably doesn't care about that minute error in calculation.
    But yeah, it's like my comp-arch teacher said. "If I have ten million dollars in the bank, and every second I add in my interest for that second, how much money do I have a year later?"

  • Double Quotes Display Question Marks

    I have some data in a tabe that is rendered as some read only output in my JHS app. This works fine in JDeveloper on Linux and JDeveloper as well as deployed on Windows. However in the version that is deployed on Red Hat the double quotes are not displaying correctly and instead display question marks in their place. The import of the database schema worked and the data is in fact double quotes. Wondering what setting I can change that makes this server treat the same data as the other environments?

    Hi,
    This sounds like a JDeveloper/ADF issue that is not related to JHeadstart. Can you please ask this question at the JDeveloper forum at JDeveloper and ADF ? Thanks!
    Regards,
    Evert-Jan de Bruin
    JHeadstart Team

  • Customized smartform decimal display error for USD currency

    Hi All,
    I have customized PO smartform. the vendor currency is USD and out of 4 po line items, only 1 Item is displaying wrong decimal.
    Say: it should display 28,089.00 but that line item displaying 28.089,00.
    But all other item are displaying correct decimals like 28,089.00.
    Please advise.
    ANu.

    Check in debug mode what values are there in the internal table.Check the format. Plus lets say i have 2 line items of different currency and i am using the above mentioned steps then it can happen
    Nabheet

  • JDev 9.0.3.3 - float/double in the debugger

    Hello!
    I use JDeveloper ver. 9.0.3.3 and during last debug session I noticed one strange behaviour in the JDev debugger.
    There is a variable of type float with value of 10964.17. I see the value when I do System.out.println() of the variable. But the debugger show me value of 10964.2 !!!
    It seems like the debugger rounds the value. Also, I noticed the same behaviour with doubles too.
    What you think about it?
    I'll try to prepare a short test for the issue - when I'll have time for it.

    No need to prepare the test. I can reproduce it easily from your description.
    It only happens when debugging with OJVM. I've entered bug #3455484.
    Sorry for the bug.
    Thanks for the report.
    -Liz Looney

  • Double number Display problem

    Hi,
    in my programe i have the following calculation
    double a= 12;
    double b= 74;
    tonum = Math.pow(a,b);
    charcount = new Double(count).toString();
    System.out.println("The value of charcount is : "+ charcount);
    when i do this it displays "7.234561410946297E79"
    how do i display the number without this "E" ??
    thanks

    The problem is you cannot get 7*10^79 into a long.
    I slammed out this code:
    <code>
    import java.text.NumberFormat;
    public class Test {
         public static void main( String[] arg ) {
              double d = 7.234561410946297E79;
              System.out.println( NumberFormat.getInstance().format( d ));
    </code>
    and got this output:
    72,345,614,109,462,970,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000
    Probably still not exactly what you are looking for, but take a look at the NumberFormat class and see if you think it will work for you.
    }

  • Upgrade to OS4 created a double-size display

    After upgrading to OS4, the display on my iPhone 3GS blew up to 2+ times its normal size. Have tried reloading the software and 'restoring' the settings but nothing has helped. I now have an iPad-size display on a much smaller, iPhone screen.
    Any suggestions?

    Double tap the screen with 3 fingers and then turn Accessibility off in Settings.

  • ProC cannot insert float/double C datatype

    Hallo,
    we compiled our C-Programms which we developed on SCO OpenServer
    with the ProC on Linux.
    Like on SCO we use the LANG enviroment variable de_DE for
    german national language support. If we try now this C-Code:
    setlocale(LC_ALL, "");
    double x = 2.34;
    EXEC SQL INSERT INTO anytable VALUES (:x);
    EXEC SQL COMMIT;
    (The table anytable has one column with number(10,4) )
    The result is that the value in table is only 2 instead of
    2,34 (german decimal separator is ,).
    If we try setlocale(LC_ALL, "C") the value in the table is
    correct 2,34.
    But we have to use the german national language
    support with setlocale(LC_ALL, "") for other purposes.
    So is it a bug or did we miss something.
    (On SCO it works with setlocale(LC_ALL, "");)
    Thanks !
    Reinhold Berger
    null

    i think you need to debug your code, lookalike the values you trying insert already exist in the database.
    these two IDs (6323df8a-5c57-4d3e-a477-09aa8b66100a, 7ae114df-9d52-4b08-affa-8c544cbc27b6).
    i would try to run the select command against the content db.
    SELECT TOP *  FROM [DB Name].[dbo].[NavNodes] where id = '6323df8a-5c57-4d3e-a477-09aa8b66100a'
    Please remember to mark your question as answered &Vote helpful,if this solves/helps your problem. ****************************************************************************************** Thanks -WS MCITP(SharePoint 2010, 2013) Blog: http://wscheema.com/blog

Maybe you are looking for