Format number of digit for a double value

Hello all
How I can format a double value so that there are only 2 values after the dot.
For example
2.332332 -> 2.33
3.1 -> 3.10
Thank you for your help
shuhu

Yeah, I keep forgetting about printf but if you are stuck with < 1.5 you have to go with DecimalFormat.

Similar Messages

  • Format-number not working for me with preview to excel

    Hi,
    I have a report with 8 fields across within a table.
    Each field is formatted in the same way, with format-number like this (there are 8):
    <?format-number:total-year-remaining;’PT999G999D99’?>
    (that's the type-your-own form-field help text in the word template).
    When I preview the PDF, the data looks fine (8 cells shown below):
    .00 (.10) (.10) .00 (.50) (.50) (.60) (.60)
    But when previewing to Excel, there are two problems:
    1. Only the data in the last field (the 8th one) is formatted with the oracle mask:
    (.60)
    But upon closer inspection, there are two blank spaces after the number in that cell, and the value itself is treated like a string, e.g. '(.60) '. In fact if I ask excel to format this cell like a number with currency and two decimal places, in won't do it because of trailing spaces. Its just not a number to excel at that point. Probably the ('s don't help things either.
    2. The data in the first seven fields in excel are numeric, and I can format them in excel as currency, but I wanted XMLP to handle this, not the excel user.
    The bottom line is this: I want both PDF and excel output. I want both forms to have the fomat mask applied correctly. And I want excel to treat each cell as a number. Is this possible?
    Thanks
    Adam

    Anatoli,
    Hello!
    I don't know if my situation is the same as yours, but after a lot of head-scratching, forum searching and template rebuilding, I finally figured out my problem.
    I had one column that no matter what I did kept appearing in Excel as text. I'd format it to Number in Excel and nothing. When trying to sum the column, Excel would not recognize any of the values as numbers. I even did the reformatting on the XML Word template to number, and the currency format that Adam mentions. Still no go. The $ and ',' appeared, but column still formatted as string.
    I just finally noticed Adam's mention of the 2 extra spaces at the end of the numbers and sure enough mine was doing the same thing. Take out the 2 spaces and voila! Number!
    Every time I redid my template in Word (07 and 03), I used the wizard. (Add-ins>Insert>Table>Wizard) walked through the steps, not really changing anything. Then I would preview and the spaces would be there. The column that I was having problems with was the last column of the table, which would get the text 'end G_ASSIGNED_CC' inserted in after the field name - separated by 2 spaces. Once I took out these two spaces, so the column now shows 'COSTend G_ASSIGNED_CC', it worked fine in Excel - all numbers.
    Hope that helps someone out there as I was having a heck of a time finding anything (solutions anyway) on this.
    Thanks,
    Janel

  • Rounding xs:double value

    Hi in bea xquery function pallette we only foung round() for decimal type.But we had a requirement to round xs:double values.
    How can i achive this ,any method for round double values or to convert double to decimal.

    does round( $someDouble ) not work?
    Can you please try a few things yourself before posting?
    If you already have, can you please post what you have tried?

  • Formatting Double value.

    Hai all,
    Please help me in this........
    I have to set Double value in JTable with two fraction digit (example: 111.00)
    I tried fromatters but all formatters returning a String.
    I f set as a string it shows me as 111.00 If i set as a Double It shows me as 111.0.
    help me in this.
    Regards,
    Suresh Dhandauthapani.

    I'm writing a loop that tallies a series of values and
    then I have to calculate the percentages and display
    itSo you have number array?
    1st loop: get the total
    2nd loop:
    a. calculate the percentage
    b. format the result using java.text.DecimalFormat
    c. display it
    >
    It would be nice if I could simply write a for loop
    that will output this data
    using flowlayout.
    No, use java.awt.GridLayout and drop the (formatted) results onto an array of labels in the second loop.

  • How can I format the double value?

    Hi,
    I am trying to format the double variable as like,
    double var = 1234.56789
    but i want that variable as like var = 1234.56
    How can i do that in java?
    Please help me.
    From
    Parshuram Walunjkar

    Try something like the following, assume the variable 'd' underneath is your double value that you want to format.
    double d = 4.45678;
    NumberFormat nf = NumberFormat.getNumberInstance();
    nf.setMaximumFractionDigits(5);
    nf.setMinimumFractionDigits(5);
    String number = nf.format(d);
    Then use the string "number" for printing out.

  • How to keep 2 decimal places for double value

    Hi,
    I need rounding function, which should round a double number till 2 digits, if there is no decimal part it should append 2 zero's in decimal places.
    eg. 100 --- > 100.00
    200.234 --> 200.23.
    I tried with Number class. but it is returning string, from that string if I try to convert to double value, it is rounding off one digit.
    Can any one help on this problem.
    Thanks,
    Suman.ch

    I am using xmlBeans using that I need to write this
    rounded value into a xml file, for that I need only
    double value with 2 decimal places.You can probably write the value as a String instead of a double somehow, so you can use the DecimalFormat class.
    You could try their mailing-lists for users/developers:
    http://xmlbeans.apache.org/community/index.html

  • Format-number,decimal not giving desired output for PO Print report XSL-FO

    Hi All,
    My requirement was to get the Unit price in european format which is 10.000,00
    Iam getting it as 10000,00 but the client needs the thousand's seperator.
    if have used the decimal seperator but iam getting the Unit Price value as 'NAN' when i submit it for an international language like Italian or Spanish
    This is what i have done
    set the decimal format
    <xsl:decimal-format name="euro" decimal-separator="," grouping-separator="."/>
    <xsl:value-of select="format-number(UNIT_PRICE, '#.###,####', 'euro')"/>
    This gives the desired output when i select the US language.
    While submitting through the conc request
    If i change the Numeric char to '.,' by clickin on Language settings..It works great
    I have tried to use the replace function but the syntax is not correct
    format-number(replace('UNIT_PRICE',',','.'), '#.###.###.###,####', 'euro')
    Any Help would be greatly appreciated.
    Thanks
    Mirza

    Hi Mirza,
    I'm struggling having the same problem. Have you found any solution?
    Best regards
    Kenneth

  • Create an NSString for number in scientific notation from double?

    Hi
    Given a double, I want to create a string in scientific notation.
    e.g for a double with a value of 123.456, I want the NSString to be "1.23456e+2" for entering in to a UITextField.
    I've looked through the docs but can't find a formatter. (There is mention of "%a" being scientific format, but it produces hex output.)
    Thanks for any clues.
    Steve

    Here, you should find what you are looking for:
    http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Strings/Ar ticles/FormatStrings.html#//apple_ref/doc/uid/20000943
    http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Strings/Ar ticles/FormatStrings.html#//apple_ref/doc/uid/20000943
    http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/ Classes/NSStringClass/Reference/NSString.html#//appleref/occ/clm/NSString/stringWithFormat:

  • Round a double value to a specific number of decimal places?

    Hello,
    Is there standard java function which will round a double value to a specified number of decimal places? Something like:
    double d = 4.34523;
    d = round(d, 2);
    where d is finally assigned the value of 4.34?
    Thanks!
    -exits

    No, because doubles hold values in binary (as do all values in a computer, of course, but there's no additional stuff to indicate decimal values).
    If you want values with specific rounding rules in decimal, use java.math.BigDecimal.
    If you just want to format the number with a specified number of decimal digits, use java.text.DecimalNumber.

  • Need some help in Rounding a double value to a whole number

    Hey Peeps,
    Need some help here, I got a method that returns a value in double after a series of calculation.
    I need to know how can I round the double value, so for example,
    1. if the value is 62222.22222222, it rounds to 62222 and
    2. if the value is 15555.555555, it rounds to 15556
    How can i do this
    Zub

    Hi Keerthi- Try this...
    1. if the value is 62222.22222222, it rounds to 62222 and
    double d = 62222.22222222;long l = (int)Math.round(d * 100); // truncatesd = l / 100.0;
    double d = 62222.22222222;
    System.out.println(d);
    long l = (int)Math.round(d * 100);
    // truncatesSystem.out.println(l);
    d = l / 100.0;System.out.println(d);
    for (int i = 0; i < 1000; i++)
    {    d -= 0.1;}
    for (int i = 0; i < 1000; i++)
    {    d += 0.1;}System.out.println(d);
    regards- Julie Bunavicz
    Output:
    62222.22222222
    62222
    62222.22
    62222.22000000000001

  • Impact on roaming profile accounts if we Change User logon Name to Employee Number format in Active Directory for all User accounts

    I want to understand if we change User logon Name to Employee Number format in Active Directory for all User accounts, then what would be the impact on existing profile. Whether we need to change it manualy or it will connect to same profiles in terminal
    session.
    As i observed it create new profile after logon name changed to employee number where existing users profile settings get fails to load and prompt for new settings (such as outlook reconfiguration, share drive mapping etc.).
    Kindly let me know the proper process to overcome with this, how to connect same existing roaming profile with employee number format change.

    Hi,
    What if we change the user name of user account, will it have impact on roaming profiles.
    Yes, it will affect roaming profiles. Please rename the roaming profile folder as the new user account name, in addition, change the profile path in ADUC.
    Here is an related article below for you:
    How to Rename a Windows 7 User Account and Related Profile Folder
    http://social.technet.microsoft.com/wiki/contents/articles/19834.how-to-rename-a-windows-7-user-account-and-related-profile-folder.aspx
    Best Regards,
    Amy

  • DVWP XSLT count number of column having Yes/No values for each row

    I have a Data View Web Part .Now I have a column that contains either 'Yes' or 'No'
    and i want to count the number of 'Yes' for the rows and column  .
    below image will help to understand better what i am tying to achieve.  

    Here is XSLT code , you may find this usefull
    Row View Template :
    <xsl:template name="dvt_1.rowview">
          <xsl:param name="Rows"/>
          <xsl:variable name="CountYesForAll" select="number((. = contains(@Richard,'Yes')))
           +number((. = contains(@AndrewP,'Yes')))
           +number((. = contains(@Damien,'Yes')))
           +number((. = contains(@AndrewC,'Yes')))
           +number((. = contains(@Tiffany,'Yes')))
           +number((. = contains(@David,'Yes')))
           +number((. = contains(@Tony,'Yes')))
           +number((. = contains(@Saj,'Yes')))
           +number((. = contains(@Miguel,'Yes')))
           +number((. = contains(@Viv,'Yes')))
           +number((. = contains(@Paula,'Yes')))
           +number((. = contains(@Helen,'Yes')))
           +number((. = contains(@Matthew,'Yes')))"/>
          <xsl:variable name="RichardsCount" select="count($Rows[(@Richard)='Yes'])"></xsl:variable>
          <xsl:variable name="AndrewPsCount" select="count($Rows[(@AndrewP)='Yes'])"></xsl:variable>
          <xsl:variable name="DamiensCount" select="count($Rows[(@Damien)='Yes'])"></xsl:variable>
          <xsl:variable name="AndrewCsCount" select="count($Rows[(@AndrewC)='Yes'])"></xsl:variable>
          <xsl:variable name="TiffanysCount" select="count($Rows[(@Tiffany)='Yes'])"></xsl:variable>
          <xsl:variable name="DavidsCount" select="count($Rows[(@David)='Yes'])"></xsl:variable>
          <xsl:variable name="TonysCount" select="count($Rows[(@Tony)='Yes'])"></xsl:variable>
          <xsl:variable name="SajsCount" select="count($Rows[(@Saj)='Yes'])"></xsl:variable>
          <xsl:variable name="MiguelsCount" select="count($Rows[(@Miguel)='Yes'])"></xsl:variable>
          <xsl:variable name="VivsCount" select="count($Rows[(@Viv)='Yes'])"></xsl:variable>
          <xsl:variable name="PaulasCount" select="count($Rows[(@Paula)='Yes'])"></xsl:variable>
          <xsl:variable name="HelensCount" select="count($Rows[(@Helen)='Yes'])"></xsl:variable>
          <xsl:variable name="MatthewsCount" select="count($Rows[(@Matthew)='Yes'])"></xsl:variable>
      <tr>
       <xsl:if test="position() mod 2 = 1">
        <xsl:attribute name="class">ms-alternating</xsl:attribute>
       </xsl:if>
       <xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">
        <td class="ms-vb" width="1%" nowrap="nowrap">
         <span ddwrt:amkeyfield="ID" ddwrt:amkeyvalue="ddwrt:EscapeDelims(string(@ID))" ddwrt:ammode="view"></span>
        </td>
       </xsl:if>
       <td class="ms-vb">
        <xsl:value-of select="@Title"/>
       </td>
       <td class="ms-vb">
        <xsl:attribute name="style">
         <xsl:if test="normalize-space(@Richard) = 'NA'">background-color: #000000;</xsl:if>
        </xsl:attribute>
        <xsl:value-of select="@Richard"/>
       </td>
       <td class="ms-vb">
        <xsl:attribute name="style">
         <xsl:if test="normalize-space(@AndrewP) = 'NA'">background-color: #000000;</xsl:if>
        </xsl:attribute>
        <xsl:value-of select="@AndrewP"/>
       </td>
       <td class="ms-vb">
        <xsl:attribute name="style">
         <xsl:if test="normalize-space(@Damien) = 'NA'">background-color: #000000;</xsl:if>
        </xsl:attribute>
        <xsl:value-of select="@Damien"/>
       </td>
       <td class="ms-vb">
        <xsl:attribute name="style">
         <xsl:if test="normalize-space(@AndrewC) = 'NA'">background-color: #000000;</xsl:if>
        </xsl:attribute>
        <xsl:value-of select="@AndrewC"/>
       </td>
       <td class="ms-vb">
        <xsl:attribute name="style">
         <xsl:if test="normalize-space(@Tiffany) = 'NA'">background-color: #000000;</xsl:if>
        </xsl:attribute>
        <xsl:value-of select="@Tiffany"/>
       </td>
       <td class="ms-vb">
        <xsl:attribute name="style">
         <xsl:if test="normalize-space(@David) = 'NA'">background-color: #000000;</xsl:if>
        </xsl:attribute>
        <xsl:value-of select="@David"/>
       </td>
       <td class="ms-vb">
        <xsl:attribute name="style">
         <xsl:if test="normalize-space(@Tony) = 'NA'">background-color: #000000;</xsl:if>
        </xsl:attribute>
        <xsl:value-of select="@Tony"/>
       </td>
       <td class="ms-vb">
        <xsl:attribute name="style">
         <xsl:if test="normalize-space(@Saj) = 'NA'">background-color: #000000;</xsl:if>
        </xsl:attribute>
        <xsl:value-of select="@Saj"/>
       </td>
       <td class="ms-vb">
        <xsl:attribute name="style">
         <xsl:if test="normalize-space(@Miguel) = 'NA'">background-color: #000000;</xsl:if>
        </xsl:attribute>
        <xsl:value-of select="@Miguel"/>
       </td>
       <td class="ms-vb">
        <xsl:attribute name="style">
         <xsl:if test="normalize-space(@Viv) = 'NA'">background-color: #000000;</xsl:if>
        </xsl:attribute>
        <xsl:value-of select="@Viv"/>
       </td>
       <td class="ms-vb">
        <xsl:attribute name="style">
         <xsl:if test="normalize-space(@Paula) = 'NA'">background-color: #000000;</xsl:if>
        </xsl:attribute>
        <xsl:value-of select="@Paula"/>
       </td>
       <td class="ms-vb">
        <xsl:attribute name="style">
         <xsl:if test="normalize-space(@Helen) = 'NA'">background-color: #000000;</xsl:if>
        </xsl:attribute>
        <xsl:value-of select="@Helen"/>
       </td>
       <td class="ms-vb">
        <xsl:attribute name="style">
         <xsl:if test="normalize-space(@Matthew) = 'NA'">background-color: #000000;</xsl:if>
        </xsl:attribute>
        <xsl:value-of select="@Matthew"/>
       </td>
       <td>
       <xsl:value-of select="$CountYesForAll"/>
       </td>
       <td>
        <xsl:if test="normalize-space(@Title) = 'Richard'">
         <xsl:value-of select="$CountYesForAll + $RichardsCount"/>
        </xsl:if>
        <xsl:if test="normalize-space(@Title) = 'Andrew P'">
         <xsl:value-of select="$CountYesForAll + $AndrewPsCount"/>
        </xsl:if>
        <xsl:if test="normalize-space(@Title) = 'Damien'">
         <xsl:value-of select="$CountYesForAll + $DamiensCount"/>
        </xsl:if>
        <xsl:if test="normalize-space(@Title) = 'Andrew C'">
         <xsl:value-of select="$CountYesForAll + $AndrewCsCount"/>
        </xsl:if>
        <xsl:if test="normalize-space(@Title) = 'Tiffany'">
         <xsl:value-of select="$CountYesForAll + $TiffanysCount"/>
        </xsl:if>
        <xsl:if test="normalize-space(@Title) = 'David'">
         <xsl:value-of select="$CountYesForAll + $DavidsCount"/>
        </xsl:if>
        <xsl:if test="normalize-space(@Title) = 'Tony'">
         <xsl:value-of select="$CountYesForAll + $TonysCount"/>
        </xsl:if>
        <xsl:if test="normalize-space(@Title) = 'Saj'">
         <xsl:value-of select="$CountYesForAll + $SajsCount"/>
        </xsl:if>
        <xsl:if test="normalize-space(@Title) = 'Miguel'">
         <xsl:value-of select="$CountYesForAll + $MiguelsCount"/>
        </xsl:if>
        <xsl:if test="normalize-space(@Title) = 'Viv'">
         <xsl:value-of select="$CountYesForAll + $VivsCount"/>
        </xsl:if>
        <xsl:if test="normalize-space(@Title) = 'Paula'">
         <xsl:value-of select="$CountYesForAll + $PaulasCount"/>
        </xsl:if>
        <xsl:if test="normalize-space(@Title) = 'Helen'">
         <xsl:value-of select="$CountYesForAll + $HelensCount"/>
        </xsl:if>
        <xsl:if test="normalize-space(@Title) = 'Matthew'">
         <xsl:value-of select="$CountYesForAll + $MatthewsCount"/>
        </xsl:if>
       </td>
      </tr>
     </xsl:template>
    Footer template to show sub total :
    <xsl:template name="dvt_1.footer">
      <xsl:param name="Rows" />
      <div class="bupareport">    
        <table border="0" width="100%" cellpadding="2" cellspacing="0">
       <tr>
        <td width="8%">Sub Total :</td>
        <td width="6%"> <xsl:value-of select="count($Rows[(@Richard)='Yes'])" /></td>
        <td width="6%"> <xsl:value-of select="count($Rows[(@AndrewP)='Yes'])" /></td>
        <td width="6%"> <xsl:value-of select="count($Rows[(@Damien)='Yes'])" /></td>
        <td width="6%"> <xsl:value-of select="count($Rows[(@AndrewC)='Yes'])" /></td>
        <td width="6%"> <xsl:value-of select="count($Rows[(@Tiffany)='Yes'])" /></td>
        <td width="6%"> <xsl:value-of select="count($Rows[(@David)='Yes'])" /></td>
        <td width="6%"> <xsl:value-of select="count($Rows[(@Tony)='Yes'])" /></td>
        <td width="6%"> <xsl:value-of select="count($Rows[(@Saj)='Yes'])" /></td>
        <td width="6%"> <xsl:value-of select="count($Rows[(@Miguel)='Yes'])" /></td>
        <td width="6%"> <xsl:value-of select="count($Rows[(@Viv)='Yes'])" /></td>
        <td width="6%"> <xsl:value-of select="count($Rows[(@Paula)='Yes'])" /></td>
        <td width="6%"> <xsl:value-of select="count($Rows[(@Helen)='Yes'])" /></td>
        <td width="6%"> <xsl:value-of select="count($Rows[(@Matthew)='Yes'])" /></td>
        <td width="6%"> </td>
        <td width="8%"> <xsl:value-of select="@AndrewP"> </xsl:value-of></td>
       </tr>
      </table>
      </div>
     </xsl:template>

  • Dealing with exponents for double values...

    Hi all,
    I've been putzing around with the NumberFormat class, as well as the Double api, but I can't seem to find a solution on how to remove exponents from double values.
    For example:
    double x = Double.MIN_VALUE;
    Might return 4.9E-123
    How do I remove the E, or any of those special characters, and just retrieve the exact, unshortened value?

    For example:
    double x = Double.MIN_VALUE;
    Might return 4.9E-123It doesn't return 4.9E-123. It returns a double. If you print it out it will look like that.

  • Add a new format number for everyone in webi

    Hi,
    I would like to add specific format number and date in webi for all my users.
    I would like to add them in the window "Format number" in the custom.
    I know it is possible to add in a report but when you start a new report you lose it. I want persistent format number.
    I check the "defaultconfig.xml" file, But I didn't see anything about format number, I think this default config file is more about the skin : bg color, image, cell colors, borders .....
    Any idea to do so ?
    Thank you.
    C.

    hi,
    You can set 'object format' in Universe for selected objects.
    Go to Universe.
    select the required object.
    Right click and select 'Object Format'.
    whenever user uses these objects in WEBI report creation, format is preserved.
    Regards,
    Vamsee

  • DecimalFormat for Double value

    hi all,
    I have one problem that is
    I have Double value like 96.44444 but I want
    96.4 only means only one decimal point after the value
    so could anyone send the solution...
    I think we can solve this problem by using "DecimalFormat" ...
    but I don't know how...
    thanks
    byee

    yes, we can...
    here goes:
    DecimalFormat df=new DecimalFormat("#.#")
    to use it:
    ... df.format(your_value);

Maybe you are looking for