Calculate with decimals

How to do calculations in Java where I have to ignore decimals
for example:
a = 101.46456
b = 10000
c = 10000 * 101.464
I want to use only 3 decimals and ignore if there are more than three.
Thanks

What do you mean "ignore decimals"? Are you spcifically required to trunctate or round the raw inputs before sending them to the calculation? The usual way of doing things would be to use all inputs to their full precision, and then just format the output with java.text.DecimalFormat.
If you really need to get rid of >= 4th decimal place before calculating, then the conversion to int, multiply, divide described in another post is a pretty straightforward solution, but it has the disadvantage that the magnitude of your float or double may be larger than Integer.MAX_VALUE / 1000.
Another approach would be to use a DecimalFormat to format the number to a String w/ at most 3 digits right of decimal, and then parse it back into a number.
However, what would you do with this?
a = 0.00000000123456
b = 1000000000000
c = a * b
Do you first normalize a to 1.23456E-9 and then truncate/round to 1.234E-9, s.t. a * b = 1.234E3? Or do you do the "ignoring" first, s.t. a * b = 0.000 * 1E12 = 0?

Similar Messages

  • WithHold Tax with Decimals

    Hi,
    Is it possible to calculate the Withold Tax with value in Decimal places? i.e., If the base amount is 11111 and the withold tax % is 3 then the WT amount is 333.33 wherein SAP calculates it as 333 only. We had recently implemented B1 in Thailand and the requirement is that, the withold tax should be calculated with exact decimals and not rounded off.
    When I checked the Withold tax definition, there are only 2 options for rounding off, either to a lower amount or to a higher amount and there's no option to keep it as it is.
    Anybody has any solution?
    sriram

    Hi Adele,
    It has nothing to do with the decimal places.
    In the withold tax configuration, there are 2 types of rounding off methods available
    "commercial values" or "truncated AU" and you need to select any one of them.  commercial values setting, makes it to the next higher numeric and truncated au rounds it off to a lower value.
    There is a possibility that, at the time of carrying out the A/R or A/P transaction, the calculation can be done manually and we can enter the amount with decimals and SAP takes it as it is.  But when calculates it on it's own, then it doesn't.  That's why I wanted to know, whether anybody else is having this problem and whether they have any solution in place?
    sriram

  • Issues with Decimals

    I have an issue with decimals in calculation : -
    Data : G_SUM TYPE p DECIMALS 2.
       KOMV-KBETR = 2.00  (KBETR TYPE IS P(6) Decimal 2)
       WG_A650-ZZBILL_QUNT = 10.00 (ZZBILL_QUNT Type is P(7) Decimal 3)
            Loop at I_A650 into WG_A650.
                 G_SUM = G_SUM + ( KOMV-KBETR * WG_A650-ZZBILL_QUNT ).
            Endloop.
               XKWERT = G_SUM. (XKWERT Type is P(7) Decimal 2)
    Form the above calculation : - G_SUM should be 20.00
             But the result is : -  20000.00
    To aviod this i changed the declartion of G_SUM as below : -
    Data : G_SUM TYPE p DECIMALS 5.
    Now it is calculating correctly but i need to assign this value to a another field.
          Its data type is (TYPE p DECIMALS 2)
    Now the result is again changed to 20000.00
    Any sugesstion to fix this issue will be apprecaiated.
    Regards,
    Kittu

    Hi Florian Kemmer,
    Thank you for your quick response!
    It is my mistake, i could have explained in more efficient manner. 
    The below values are from Internal table only and it has only 1 record.
    KOMV-KBETR = 2.00    
       WG_A650-ZZBILL_QUNT = 10.00
    (G_SUM = G_SUM + ( KOMV-KBETR * WG_A650-ZZBILL_QUNT ).)
    After the above formula is executed it shoudl display the value as 20.00
    Due to issues with the decimals it is displaying as 20000.00
    And the declaration is not exactly done as described...It is just for understanding.
    KBETR --> is of type  P(6) Decimal 2.
    Any suggestion will be appreciated
    Regards,
    Kittu
    Edited by: Kittu on Mar 29, 2010 12:34 PM

  • APD-Issue with Decimals

    hi,
    I am using APD to get the report results as CSV file. I have restircted not to show the decimal places for the values in the report  but the file that is genarated always comes with two decimals.
    The business  does not wants the value with decimals.  I have looked at all the options to get this possible in APD.
    Please help with this issue. I am not good at ABAP and I may not be able to write a program.
    Regards,
    Raghu

    Hi;
    APD seeks to direct the base, then it makes sense to try to change the decimal places in the query, there is documentation that shows how to Creation of Key Figures with Higher Decimal Place Precision (https://service.sap.com/sap/support/notes/460652)
    Sá Freire
    Edited by: Luiz André Sá Freire on Feb 2, 2011 4:35 PM

  • DYNP_UPDATE_FIELDS  with decimals

    Hi all,
    I need your help i am updating fields on dynpro using FM DYNP_UPDATE_FIELDS  but the probles is that i need to display amounts with decimals and actually it is  updating without decimals. Somebody knows how can i update my field showing decimals?  Please!!!
    Thanks in advance.
    Mar.

    Hi Marisol,
    Please find the link Below
    [Fields |Updating attributes of screen table]
    Hope this will be very useful to you.
    Thanks
    Kalyan

  • KP06 cannot enter number with decimals in fxd. consumption

    Hi!
    When using transaction
    KP06 Change Cost Element/Activity Input Planning with
    Planner Profile SAP102,
    layout 1-102 Std.layout Activity input ActInd/ActDep
    we cannot enter number with decimals in field Fxd. consumption
    Field name MEF
    Data element MEFXXX
    When we enter number with decimals like 12,45 it gets rounded in 13.
    I have tried to change number format of this collumn from Not defined
    to 0,00 but this is not helping. The rounding still takes place.
    My question is where can I assign the unit (of measurement) for posting of quantities.
    Regards,
    Marina

    The UOM is assosiated with Activity Type, and has a certain number of decimal points in the definition of UOM.  The other place to influence decimal points in the proper planning layout (column settings).

  • Calculate with maximum result in formula

    Hello Experts!
    I have column where I calculate result as maximum. If I make a formula which uses this column then it calculates with the sum of the values.
    An example:
    What I search is a way to calculate with the max-value in the result line.
    E.g.:
    Value1-Value2-Quota
    Result--110--57-----51,8%
    row1-----56---7-----12,5%   
    row2----110--11-----10%
    row3-----78--39-----50%
    What should be calculated is 57/110*100
    What has been calculated is 57/244*100
    Does someone know how to do this?
    Best Regards,
    Peter

    Hello Vam,
    it depends on what you want. If you have just one field you want to calculate you could do it in my case as follows:
    Sub SAPBEXonRefresh(queryID As String, resultArea As Range)
        Dim FirstRow,  LastCol As Integer
        FirstRow = resultArea.Cells(1).Row
        LastCol = resultArea.Cells(resultArea.Cells.Count).Column
                x = Cells(FirstRow + 1, LastCol - 3).Value
                y = Cells(FirstRow + 1, LastCol - 4).Value
                Cells(FirstRow + 1, LastCol - 2).Value = x / y
    End Sub
    We have the fields we want to calculate(x, y) in our result. Source fields are 3 and 4 fields from the right edge of the result-Area. In the field 2 fields from right edge i want to calculate the result.
    All the values are there but if we calculate with a formula there is a wrong result because x and y are maximum values.
    If you want to do this for many or all lines you could do a FOR NEXT or so...
    If someone knows a better way, please post.
    Best Regards,
    Peter

  • Using Modulus (%) arithmetic operator with decimals

    When trying to use the arithmetic operator modulus with decimals there seem to be some errors in the results. Is there a restriction on the number/value of decimals that can be used with this operator? Am I perhaps just using it incorrectly?
    example ...
    Double valA= new Double("12.4");
    Double valB = new Double("1236");
    double result = valB.floatValue() % valA.floatValue();
    System.out.println("valB : " + valB );
    System.out.println("valA: " + valA);
    System.out.println("result : " + result);
    produces :
    valB : 1236.0
    valA : 12.4
    result : 8.40003776550293
    But :
    Double valA= new Double("12.5");
    Double valB = new Double("1236");
    double result = valB.floatValue() % valA.floatValue();
    System.out.println("valB : " + valB );
    System.out.println("valA: " + valA);
    System.out.println("result : " + result);
    produces :
    valB : 1236.0
    valA : 12.5
    result : 11.0

    Floating point arithmetic in general is not exact. The problem is that you are expecting exact results.
    In the second example where you use 12.5 and 1236.0 is just so happens that both of those numbers can be represented exactly, so you do get an exact result.

  • CCM2.0 Upload files with decimals in prices

    Hi experts
    We use a csv-file to upload into CCM2.0.
    We now have a problem when a price in the file is with decimals. We use "," as decimal seperator (100,25 EUR) but we can only upload prices if the decimal seperator is "." (100.25 EUR).
    I means a lot of work changing decimal seperators from "," to "." in the file from our vendors
    Do anyone have an idea how we can change this - so it is possible to upload prices with "," ?
    Thanks in advance
    Jesper

    Hi Jasper
    are you keeping 100 25 in separate column? why?
    Are you receiving the Excel file from vendor and making into CSV file ?
    csv file can delimit ; instead of ,
    if  you want to make delimiter set up for the above file
    go to control panel ->regional and language options-> click->go to regional option tab-->right hand side you may see customize -> list separator , ( you can change so when you save excel file data into csv file and open a file with notepad mode -> you can see this file in ; instead of ,
    br
    muthu

  • Import XML und calculate with MathScript

    First how can I import my XML file to LabView. And second, how to calculate with the Data from XML with constant number. (e.g. XML Number * constant number = x)

    Hi,
    I have no expierence with import XML and reading the XML data. Even some examples I couldn't use it for my problem. I hope that someone can help me.
    I need to get every Data from XML and save every number as a local variable in LabView. So that I can work with the numbers.
    XML:
    <Numbers>
    <figure>50</figure>
    <figure2>100</figure2>
    <figure3>150</figure3>
    <figure4>200</figure4>
    <figure5>250</figure5>
    </Numbers>
    Attachments:
    Test.PNG ‏12 KB

  • Upload Quantities in BoM with decimals

    Hi,
    I cannot achieve to upload quantities with decimals for components in a BoM with the DTW. After the upload the system rounds the number to a whole number.
    Thank you.

    Hi Oscar...
    Check with this link
    http://scn.sap.com/thread/3146841
    Regards
    Kennedy

  • Solver VBA SolverAdd constraints with decimals not possible

    This issue is related to the German versions of Excel, it tried all from XL2002 up to XL2013.
    I can add a constrain with decimals to the solver manually and it works as expected:
    When I record a macro the recorded constrain line is this:
    SolverAdd CellRef:="$A$1", Relation:=3, FormulaText:="0,001"
    But when I run that line the constrain is always ">= 1", the decimal part is missing! I tried all variations that I can think of, but nothing works. When I run this macro:
    Sub Makro1()
    SolverReset
    SolverAdd CellRef:="$A$1", Relation:=3, FormulaText:=0.001
    SolverAdd CellRef:="$A$1", Relation:=3, FormulaText:="0.001"
    SolverAdd CellRef:="$A$1", Relation:=3, FormulaText:="0,001"
    End Sub
    The result is this:
    How can I set a constrain with decimals into the Solver?
    Andreas.

    The answer for this from Frontline Systems Inc. is:
    This is an old VBA bug.
    Just use:
    FormulaText:="=1"
    Rather than
    FormulaText:="1"
    That sounds strange... "old VBA bug"?? VBA is able to detect and work with the language depended decimal delimiters and such things!
    So I went a little into the depths and have looked more closely at SOLVER.XLAM and there I found the bug:
    If "." <> Application.International(xlDecimalSeparator) Then
    dummy = InStr(FormulaText, Application.International(xlDecimalSeparator))
    Do While dummy <> 0
    Mid(FormulaText, dummy, 1) = "."
    dummy = InStr(FormulaText, Application.International(xlDecimalSeparator))
    Loop
    End If
    If Not IsNumeric(FormulaText) Then
    On Error Resume Next
    If TypeName(FormulaText) = "Range" And Not IsCellReference(Stylecheck(CStr(FormulaText))) Then
    FormulaText = FormulaText.Address
    End If
    FormulaText = CStr(FormulaText)
    FormulaText = Stylecheck(FormulaText)
    On Error GoTo mainerror
    Else
    FormulaText = CDbl(FormulaText)
    End If
    They replace the "," with a "." and then they call CDBL (and not VAL), that is the reason.
    In Germany (Europe) the "." is the thousand delimiter and the "," is the decimal delimiter. And CDBL knows that!
    Okay, so why does "=0,0001" work? Obvious the CBDL line isn't executed in this case.
    The solver routines creates hidden names in the sheet and store anything there. If you like to see them execute this:
    Sub ShowNames()
    Dim N As Name
    For Each N In Names
    N.Visible = True
    Next
    End Sub
    And names are also language depended, but when we want to store values into a name we have to "speak" English.
    The code changes "=0,0001" to "=0.0001" and stores that into the name manager. So when we look into the names we can see "=0,0001" at screen (in Europe).
    And the Solve routines grabs that values... what a mess. :-)
    If you want to write language-independent programs therefore this syntax is recommended:
      SolverAdd "A1", 3, "=" & 0.0001
    Andreas.

  • Calculate with DocTotal / $[$22.0.0]

    Hi,
    we want automatically to calculate the freight costs. therefor i wrote this statement :
    SELECT ($[$22.0.0]*0.035)
    But if i start the select i got a SQL failure. It is not possible to calculate with this cell ?
    It must be the displayed cell not the DocTotal from ordr, cause the calculation should be executed before
    saving the order.
    regards

    it works fine...i did not know the argument "Number". It is for formating the query output ?
    regards
    edit: it works fine, if the formated search is in the same form. but i put it into the freight form. there i get a sql statement failure.

  • Calculate with datas

    Hi NG,
    why is it not working???
    I try to calculate with a spy (xml) data. The column type is set as number.
    I calculate with the following php code (simple..code):
    $ps = "{price}";
    $ps = $ps/2;
    echo $ps;
    Its all the time 0
    If i try:
    $ps = "{price}";
    //$ps = $ps/2;
    echo $ps;
    i get the right numbers....but i will calculate them.
    i tryed  also:
    $ps = "{price}";
    $ps = (int)$ps;
    $ps = $ps/2;
    echo $ps;
    Whats my mistake????
    Or is there any other way to calculate the output???
    TELLO

    OMG - perfect. I will round them now and than its perfect.
    .V1 - one mor Question...
    Yesterday after your replay i realised, that i can not work with the spry ds and php together. Its a desaster for me now, because all my ideas are using booth ;-)
    My main problem is now, i have one externel XML, whate i can only get over a external ASP website. I get it only with the proxy trick.
    Now i make a "user they see this car, have seen also this one" ....i will build for this a mySQL db, witch i will fill / update per session....
    But now, i can not input them with php, because i dont can work with the spry ds ....
    Do you have any idea, how i can input the id´s in my mySQL?
    Or must i send the spry ID´s as array to a php and this will input them in the background?
    Is there no easyer thing?
    THank you so mutch for you help all the time!!!
    TELLO

  • Calculate with double ???

    Hi,
    I try to calculate with doubles but it does not work.
    I read from a JTextArea "ta" the user input with: String value = ta.getText();
    Then I cast value to double:
    Double x;
    try {x = Double.valueOf(value);}
    catch(NumberFormatException ex){System.out.println("Falsche Eingabe");}
    But now I want to calculate x, for example: x = x * 2.0
    Then I get the error message "incompatible type for = ..." and "incompatible type for * can't convert..."
    I get the tip to use x=Double.parseDouble(value), but the method parseDouble do not exist .... ?
    Thank Your for helping!!!
    Claudia

    Double x;
    try {x = Double.valueOf(value);}
    catch(NumberFormatException
    ex){System.out.println("Falsche Eingabe");}Double is an object, not a number. In order to use it for calculations you need to change things to look like this:
    double x;
    try { x = Double.parseDouble(value);}
    catch(NumberFormatException ex) {System.out.println("Falsche Eingabe");}Mark

Maybe you are looking for

  • Need to recover old playlists, old iTunes library will not open because it was created by a newer version?

    I have a Mac mini, have installed iTunes on it and want to find some old playlists that were lost.  I have several 'iTunes Libraries' with different dates but I cannot open any of them becauseit says they were created with a newer version of iTunes. 

  • Manually manage music and videos? Not if iTunes is involved.

    I don't do automatic syncing or music libraries, I run a recording studio and at the end of the day, I like to chuck a mix onto my phone and listen to it on the way home. Then when I get home, I might want to add some other stuff and compare it to th

  • "Enterprise manager configuration failed due to the ff... 11 g/windows 7

    I get this error message, when using DBCA to create a database. Please help! Studying on my own for OCA. Error message : "Enterprise manager configuration failed due to the following error - Listener is not up or database service is not registered wi

  • Why increase  sysaux tablespace

    Hi Experts, I have a bi-direction oracle 10GR2 stream in window 2003. I got a error message in alert. error 12801 in STREAMS process ORA-12801: error signaled in parallel query server P000 ORA-01653: unable to extend table SYS.STREAMS$_APPLY_SPILL_ME

  • [SOLVED] ePDFView won't display all pictures

    I'm having some issues with my ePDFView PDF reader. There are alot of pictures it simply won't display. About 25% of the pictures (in average) in my PDF documents shows up as grey blocks with the same shape and size as the original picture. This is t