Three decimal places in my calculation

Hi,
I have a division calculation, a/b where both a and b are int's.
now when i want the result upto 3 decimal places. i have done this.
Double d = a/b;
DecimalFormat c = new DecimalFormat("0.###");
c.format(d);
System.out.println(d);
Still I am unable to get 3 decimal places. I want 3 decimal places even for a 0 value like 0.000.
Thanks.

I have a division calculation, a/b where both a and b are int's.
now when i want the result upto 3 decimal places. i have done this.
Double d = a/b;You do know of course that d will be rounded down to the nearest int as you're doing int division here. Also d probably doesn't need to be a Double Object as double will do nicely. Something like so will do:
double d = (double)a/b; // this will do double division which is what you wantthen format it as you wish.

Similar Messages

  • Download reported data in Tunisian currency (three decimal places)

    Dear all,
    if I use the download of reported data functionalety in EC-CS (TC cx3d1) and the file format is .txt, the system can not handle the three decimal places of tunesian currency and moves the comma one digit to the left side. The values are multiplied with 10 right now.
    Do I need to change the settings somewhere or is that a known problem?
    Many thanks in advance,
    Andrea Reinecke

    Hello,
    many thanks for the quick answer. Maybe I need to specify the problem a little bit: The Tunisian currency has been set to three decimal places. The databaselist shows the values correctly, e.g. 5000,000.
    If I use transaction cx3d1 to download the values, the system converts this value into a textfile. The problem is, that the values is not 5000,00 any longer, instead of 50000. That means, everything is multiplied with 10 and the decimal places are away.
    Do you know that problem? We have it only with the tunisian dinar, but not with the Hungarian currency, which has as well three decimal places.
    Best regards and many thanks in advance,
    Andrea Reinecke

  • Purchase Order three decimal places

    Dear Experts
    I want to change purchase order decimal places to three. Standard sap setting allow two decimal places.
    My client want to create some raw material purchase orders in three decimal places. Also vendor bill is received in three decimals. But Purchase order doesn't allow three decimals, and if the same purchase order is created with two decimal places it causes huge amount difference. By this reason many purchase orders are pending. In transaction Code OY04 we can change the decimal places for currency directly. If there is any other setting to allow three decimals for mm transactions only. We have one month real time data on our production system, is it correct to change the decimal places at this stage.

    OY04 it is a oneway decision, extending yes, but removing not anymore possible then. Search OSS for more infos.
    If you allow more decimals, then this has not only effect on purchase orders, it will certainly effect your FI books as well.
    SAP predefines the currencies in its natural design.
    If a currency like dollars has smaller units like cent, then the SAP currency will show that. eg. for USD 2 decimals.
    If you need more detailed prices with more than 2 decimals, then you should use the price unit which is usually next to the price fields.
    instead of 1,0025 dollar you just enter 100,25 dollar per 100, this has the same effect. and this is available in material master and any condition, hence in PO and SA.

  • 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

  • Trying to limit the fidelity (to 2 decimal places) of a calculated value?

    Hi Everyone,
    I have a column that shows the Profit / Loss % for items sold.
    ISNULL(((T0.LineTotal - T0.StockValue) / NULLIF(T0.StockValue, 0)) * 100, 0
    Because it is possible for StockValue to be a zero (0) amount in our system it was necessary to add the NULLIF function.
    If a NULL value is detected then a value of 0 is ultimately returned. Due to the fact that there could still be a profit or a loss in this column I needed to add 'N/A', which I achieved by casting the calculation to a varchar and then applying a CASE statement, the full syntax is as follows -
    CAST(ISNULL(((T0.LineTotal - T0.StockValue) / NULLIF(T0.StockValue, 0)) * 100, 0) AS varchar) = '0.00000000000000' THEN 'N/A'
    ELSE CAST(ISNULL(((T0.LineTotal - T0.StockValue) / NULLIF(T0.StockValue, 0)) * 100, 0) AS varchar) END
    AS 'Profit / Loss %'
    My challenge is that the % for profit has an excessive level of fidelity, it currently goes to 14 decimal places (e.g.: 134.43223443223443)!
    I would like to limit the fidelity to 2 decimal places (e.g: 134.43). I have attempted to do this by 'double casting', first casting to a decimal then to a varchar (to allow for the 'N/A') -
    CAST(CAST(ISNULL(((T0.LineTotal - T0.StockValue) / NULLIF(T0.StockValue, 0)) * 100, 0) AS decimal) AS varchar)
    In this case the fidelity is not sufficient, and I lose all decimal places. If I stipulate the nature of the decimal place, e.g.: decimal(4,2), then I get an "arithmetic overflow" error.
    How can I make my results either 'N/A' or a numeric result (with 2 decimal places)?
    Any help will be greatly appreciated.
    Kind Regards,
    David

    Hi David...
    Check this
    *    Purpose: Lists the Sales History of Items by (user designated): 
    *    Item Code (range) and / or    
    *    Whs Code (range) and / or 
    *    Industry Code and / or    
    *    BP (Customer Code) 
    DECLARE @begItemCode nvarchar(20), @endItemCode nvarchar(20), @whsCode nvarchar(5), @indCode nvarchar(5), @custNo nvarchar(10) 
    SET @begItemCode = '' 
        IF @begItemCode = '' 
            SET @begItemCode = '00%' 
    SET @endItemCode = '' + 'Z' 
        IF @endItemCode = 'Z' 
            SET @endItemCode = 'ZZ%' 
    SET @whsCode = '' 
        IF @whsCode = '' 
            SET @whsCode = '%' 
    SET @indCode = '' 
        IF @indCode = '' 
            SET @indCode = '%' 
    SET @custNo = 'C000002' 
        IF @custNo = '' 
            SET @custNo = '%' 
            select tt.[Document Date],tt.[Document No.],tt.[Doc Type],tt.[Cust Code],tt.[Customer Name],tt.[Item Code],tt.[Item Description] ,
            tt.whscode, tt.[Line Net],tt.[Line Cost],tt.[Itm Avg Cost] , tt.[Profit / Loss],
            cast(round(tt.[Profit / Loss %],2,0) as decimal(18,2) ) as 'PL%',tt.[Vendor Name],tt.[Salesman Name] from (
    SELECT 
    T1.DocDate AS 'Document Date' 
    , T1.DocNum AS 'Document No.' 
    , 'Invoice' AS 'Doc Type' 
    , T1.CardCode AS 'Cust Code' 
    , T1.CardName AS 'Customer Name' 
    , T0.ItemCode AS 'Item Code' 
    , T0.Dscription AS 'Item Description' 
    , T0.Quantity AS 'Ship Qty' 
    , T0.WhsCode 
    , T0.LineTotal AS 'Line Net' 
    , T0.StockValue AS 'Line Cost' 
    , T2.AvgPrice AS 'Itm Avg Cost' 
    , (T0.LineTotal - T0.StockValue) AS 'Profit / Loss' 
    , CASE WHEN 
    --ROUND(
      CAST(ISNULL(((T0.LineTotal - T0.StockValue) / NULLIF(T0.StockValue, 0)) * 100, 0) AS varchar) = '0.00000000000000' THEN 'N/A' 
      ELSE CAST(ISNULL(((T0.LineTotal - T0.StockValue) / NULLIF(T0.StockValue, 0)) * 100, 0) AS varchar) END    
      AS 'Profit / Loss %' 
    , T4.CardName AS 'Vendor Name' 
    , T5.SlpName AS 'Salesman Name' 
    FROM  dbo.INV1 T0 
    INNER JOIN  dbo.OINV T1 ON T1.DocEntry = T0.DocEntry 
    INNER JOIN  dbo.OITM T2 ON T2.ItemCode = T0.ItemCode 
    INNER JOIN  dbo.ITM1 T3 ON T3.ItemCode = T0.ItemCode AND T3.PriceList = 1 
    INNER JOIN  DBO.OCRD T4 ON T4.CardCode = T2.CardCode 
    INNER JOIN  DBO.OSLP T5 ON T5.SlpCode = T1.SlpCode 
    WHERE T1.DocType = 'I' AND T2.OnHand > 0 AND T0.ItemCode >= @begItemCode AND T0.ItemCode <= @endItemCode AND T0.WhsCode LIKE @whsCode 
    AND T2.U_SCE_IN_Industry LIKE @indCode AND T1.CardCode LIKE @custNo 
    UNION ALL 
    SELECT 
    T10.DocDate AS 'Document Date' 
    , T10.DocNum AS 'Document No.' 
    , 'Credit' AS 'Doc Type' 
    , T10.CardCode AS 'Cust Code' 
    , T10.CardName AS 'Customer Name' 
    , T9.ItemCode AS 'Item Code' 
    , T9.Dscription AS 'Item Description' 
    , -1 * T9.Quantity AS 'Ship Qty' 
    , T9.WhsCode 
    , -1 * T9.LineTotal AS 'Line Net' 
    , -1 * T9.StockValue AS 'Line Cost' 
    , T11.AvgPrice AS 'Itm Avg Cost' 
    , -1 * (T9.LineTotal - T9.StockValue) AS 'Profit / Loss' 
    , CASE WHEN 
      CAST(ISNULL(((T9.LineTotal - T9.StockValue) / NULLIF(T9.StockValue, 0)) * -100, 0) AS varchar) = '0.00000000000000' THEN 'N/A' 
      --ELSE CAST(CAST(ISNULL(((T9.LineTotal - T9.StockValue) / NULLIF(T9.StockValue, 0)) * -100, 0) AS decimal) AS varchar) END 
      ELSE CAST(ISNULL(((T9.LineTotal - T9.StockValue) / NULLIF(T9.StockValue, 0)) * -100, 0) AS varchar) END 
      AS 'Profit / Loss %' 
    , T13.CardName AS 'Vendor Name' 
    , T14.SlpName AS 'Salesman Name' 
    FROM  dbo.RIN1 T9 
    INNER JOIN  dbo.ORIN T10 ON T10.DocEntry = T9.DocEntry 
    INNER JOIN  dbo.OITM T11 ON T11.ItemCode = T9.ItemCode 
    INNER JOIN  dbo.ITM1 T12 ON T12.ItemCode = T9.ItemCode AND T12.PriceList = 1 
    INNER JOIN  DBO.OCRD T13 ON T13.CardCode = T11.CardCode 
    INNER JOIN  DBO.OSLP T14 ON T14.SlpCode = T10.SlpCode 
    WHERE T10.DocType = 'I' AND T9.ItemCode >= @begItemCode AND T9.ItemCode <= @endItemCode AND T9.WhsCode LIKE @whsCode 
    AND T11.U_SCE_IN_Industry LIKE @indCode AND T10.CardCode LIKE @custNo  
      ) as tt
    Hope Helpful
    Regards
    Kennedy

  • Displaying Currency with three decimal places in smartform

    hi abap experts~~
    I'm wondering that how to convert numeric type to currency type.
    for example below.
    ex) 2346.856 --> 2.346,856
    please help me to solve the problem..
    Regards,
    Himanshu

    Hi Himanshu,
    This depends on the SU3 settings of ur system. GO to
    tcode SU3>Defaults->decimal notation..
    There change to ur desired type and relogin.
    The format will change...

  • U261B An Issue due to 3 Decimal Places in Percentage - Help Required

    I've an Issue in BEX report output, which is like when I try to create a 'Percentage' computation on a Key Figure Value, I'm getting 3 decimal places as 'default' output.
    The 'Calculations' settings I made for this KF is
    > Calculate Result as ... Nothing Defined
    > Calculate Single Values as .... Normalize According to Next Group Level Result
    > [✔] Apply to results
    > Calculation Direction - Along Rows
    ☹  I ran SAP_RSADMIN_MAINTAIN and set object 'IGNORE_T006_ANDEC' to the value 'X' - Not woking! Should I choose Update/Insert/Delete??
    ☹  T006-ANDEC & T006-DECAN for '%' has 0 decimal places only. Am I checking the correct stuff?
    ☹  OSS note 866505 not helpful for my issue. BW 7.0 Stack
    I'm getting my output as expected, but the only worrying factor is 3 decimal places due to the 'Calculations'. I'm unable to resolve using existing methods. Should I raise an OSS Note for this?
    Please help...

    Hi, I posted a message to SAP on this topic and got an explanation - it is a behaviour that cannot be changed in certain cases:
    it is the known design that it is always displayed with three decimal
    places for normalized values and the setting in Query Designer for
    decimal place doesn't take effect. This is because that normalization
    changes the number dimension of this structure element.
    You may refer to below notes about more details.
    > 869135 Decimal places and scaling for "Calculate Single Values As"
    You cannot set the number of decimal places or the scaling for some
    columns or structural components.
    For 2: Some "Calculate As" functions change the number dimension of a
    KID. In this case, the scaling and the number of decimal places set for
    the KID are no longer relevant. In this case, the system ignores the
    original setting and selects a setting that corresponds to the new
    number dimension. This cannot be overwritten. The following functions
    are affected:
    Calculate Single Values as Scale to Result, Overall Result or Query
    Result: Scaling 1 and three decimal places.
    > 501930 Number of decimal places setting is not applied
    As a result, normalized values resulting from the list calculation are
    displayed with three decimal places and without scaling by default.
    best regards, thom

  • Decimal Places of Key Figure not displaying Correctly

    Hi BW Gurus,
    I have a key Fig ZLENGTH of type Quantity. I am calculating length in Kilo Meters with this.When I am trying to load the data in my cube with flat file say if value for length is 8.123 Km it is showing in Cube 8.000 . As cklient requirement is for three decimal places I want to show exact value i.e. 8.123KM
    Pls. help. Matter Urgent
    Regards,
    MANDAR

    Hi,
    in CUNI select LENGTH in front of Units of Measurement, click the button and then double click the KM row to open its properties.
    Deciaml rounding should be empty there; if this is the case you'll have to simulate your update in order to see where the system is removing the decimals.
    Check that the original record in the PSA has decimals.
    Check that the communication structure record has decimals.
    Finally the data target record.
    It must happen somewhere in the dataflow.
    hope this helps...
    Olivier.
    Message was edited by:
            Olivier Cora

  • Three Decimal Currency

    Hi All,
    I have changed in T-code OY04 currency (JOD) decimal 2 to 3.
    i have done PO & checked its showing three decimal value its ok, i assigned taxcode 4% but its shown only 2 decimal places.
    second thing i have checked table EKPO the field NETWR value shows 2 decimal places.
    example in PO NETWR is 100.234 & in Table showing 1002.34 so i am not getting correct answer, also tax calculate on NETWR so its wrong calculation.
    please guide me, if any config related please suggest me.
    Thanks
    Best Regards
    Sachin

    Hello,
    many thanks for the quick answer. Maybe I need to specify the problem a little bit: The Tunisian currency has been set to three decimal places. The databaselist shows the values correctly, e.g. 5000,000.
    If I use transaction cx3d1 to download the values, the system converts this value into a textfile. The problem is, that the values is not 5000,00 any longer, instead of 50000. That means, everything is multiplied with 10 and the decimal places are away.
    Do you know that problem? We have it only with the tunisian dinar, but not with the Hungarian currency, which has as well three decimal places.
    Best regards and many thanks in advance,
    Andrea Reinecke

  • How to set the number of decimal places.

    Just wondering what and where the code would be to set the number of decimal places when calculating an answer.

    Depending on exactly what result you want you could alternatively format the result to a set number of decimal places.
    This is not so good for financial applications where they want the total of 10 transactions to match the total of each number displayed but can be kind of important for scientific ones.
    eg
    someNumber.ToString("N3"));
    Gives you three decimal places without changing the someNumber.
    If this turned out to be wpf then you have stringformat you can use on a binding.
    Hope that helps.
    Recent Technet articles:
    Property List Editing ;  
    Dynamic XAML

  • Decimal places in excel

    Hi,
       I am sending quantity field to excel with three decimal places but when I open the excel after generating it shows only two decimal places.How can i obtain this function with excel it should show only 3 decimal places with thousand seperator.
    Regards,
    Karthik.k

    Hi,
    if you are sending your data with OLE try something like this:
    SET PROPERTY OF GS_CELL1 'NumberFormat' = '#,##0.000'.
    Kostas

  • Decimal places in the BCC field

    Hello,
    I created a field in the xml to save a field of type double, but only allows up to three decimal places.
    <property name="freight" data-type="double" column-name="freight" display-name-resource="freight" category-resource="categoryBasics" >
         <attribute name="propertySortPriority" value="50" />
    </property>
    with sql for the column freight
    freight
    number(28, 20)
    NULL
    I noticed that this also occurs in other fields in BCC,
    Is it possible to increase the number of decimal places for a property?
    thanks.

    Hi,
    I created the view mapping as your orientations and looked like this
    <add-item item-descriptor="itemMapping" id="AmImTest">
      <set-property name="itemName"><![CDATA[test]]></set-property>
      <set-property name="description"><![CDATA[AssetManager Test itemMapping]]></set-property>
      <set-property name="mode"><![CDATA[AmMmDef]]></set-property>
      <set-property name="viewMappings"><![CDATA[ivM1]]></set-property>
      <set-property name="formHandler"><![CDATA[AmFhDef]]></set-property>
      <set-property name="itemPath"><![CDATA[/atg/multisite/SiteRepository]]></set-property>
      <set-property name="name"><![CDATA[AssetManager]]></set-property>
    </add-item>
    <add-item item-descriptor="itemViewMapping" id="ivM1">
      <set-property name="propertyMappings"><![CDATA[propertyViewMapping=pvM1]]></set-property>
      <set-property name="attributeValues"><![CDATA[includedProperties=av1]]></set-property>
      <set-property name="displayName"><![[scopus.geralProperties]]></set-property>
      <set-property name="name"><![CDATA[ item View Mappi]]></set-property>
    </add-item>
    <add-item item-descriptor="attributeValue" id="av1">
      <set-property name="value"><![CDATA[id,name,description,freight]]></set-property>
    </add-item>
    <add-item item-descriptor="propertyViewMapping" id="pvM1">
      <set-property name="propertyView"><![CDATA[pv1]]></set-property>
    </add-item>
    <add-item item-descriptor="propertyView" id="pv1">
      <set-property name="description"><![CDATA[BIZUI Basic editor for double properties with more than 3 decimal characters.]]></set-property>
      <set-property name="attributes"><![CDATA[inputFieldMaxlength=pvAtrDef1]]></set-property>
      <set-property name="mode"><![CDATA[aMgrMmView]]></set-property>
      <set-property name="isComponentPropertyView"><![CDATA[false]]></set-property>
      <set-property name="isReadOnly"><![CDATA[false]]></set-property>
      <set-property name="type"><![CDATA[double]]></set-property>
      <set-property name="name"><![CDATA[SCO BIZUI with more than 3 decimal characters.]]></set-property>
    </add-item>
    Did I missed something?

  • 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.

  • 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.

    Create one more variable in Global definitions with only 1 decimal place.
    Assign value of qty to this new variable.
    SAP automatically takes care of the rounding.
    And then print this new variable rather than qty.
    You can write all these in a code block.

  • Terminating Decimal places in Appraisal Scales

    Hi All,
    When I am using numerical scale in appraisals, it gives the values with three decimal places.. Ex: 5 is displayed as 5,000. 
    Can anybody tell me how to terminate the decimal places in scales..
    Thank you in advance
    Regards
    Syed

    Syed,
    How did you resolved this ?
    Aneez

Maybe you are looking for

  • How do I install the Macro Media Player?

    Im currently taking an online test for my college course and I cannot proceed without first downloading the macromedia player but Im unable to click the download link because I "need a plugin". PLease help.

  • Adobe Illustrator CS6 Sneak Peek: Pattern Creation | Adobe Design Center | Adobe TV

    Join Brenda Sutherland, Illustrator product manager, and she shares an exciting new way to create seamless, repeating vector patterns in Illustrator CS6. http://adobe.ly/GHWIbW

  • Loss of quality between iMovie '09 and iDVD

    Hi all, I'd like to have some advises to understand if what I'm doing is the right way to do or if there is a better/different solution. I'm working in a photo shop (not ADOBE Photoshop ... ;-)) and sometimes we are doing some "movies" from photos. I

  • Unable to find user & shared folders

    I tried to create a BI publisher report based on BI Answers request. I opened the template from the MS word also. In the Oracle BI workspace the Users & shared folder is not showing. Can anyone tell me how to resolve this.

  • I want to take a SQL Server DBA L3 Handover in my new company

    Actually I have joined a new company and appoint as L3,I want to take Handover. I want to take a SQL Server DBA L3 Handover in my new company. Is there any process pdf / website or excel which I can follow. Thanks