Rounding off to nearest decimal point

i have these values
35.2
35.3
35.4
35.5
35.7
35.8
35.9
36.0
i am looking for indexes closet 35.74 in my array. (which is index 4.)
i used the "round to nearest" function and it gave me 36.
which is index 7.
what other ways to get the right index?
Solved!
Go to Solution.

You will always have some difficulties with rounding to a specific number of digits after the decimal point because of the way numbers are represented in binary. When expressed in binary 0.1 is an infinitely repeating expression. Regardless of the display the internal representation of the number always uses the maximum resolution for the data type (8 bytes for DBL).
So you need to be very careful to define exactly what you  want. If you have an array of values (regardless of the way they are displayed) Then you can find the closest to a Test Value by subtracting Test Value from the array and finding the minimum of the absolute values of the differences.
Note that in the image below the same values are in Array and Array 2 with the display on Array 2 set for 20 siginficant digits. 
Lynn

Similar Messages

  • Round off to two decimal places

    hi
    i have a filed in it values are there i want to round off to two decimal places
    which is the function module for it please suggest
    regards
    Arora

    Hi Nishant Arora,
    Please check this code.
    DATA: N1 TYPE P DECIMALS 4 VALUE '0.0565',
               N2 TYPE P DECIMALS 2.
    MOVE N1 TO N2.
    WRITE: N2.
    Here the value is get rounded to 0.06.
    Rather than function modules you go with this. I think it is easier.
    Reward points if useful.
    Cheers,
    Swamy Kunche

  • Price per unit is getting round off to two decimal places.

    Hi Gurus,
    In the Billing output, the Price per unit is getting round off to two decimal places.
    How can we avoid this or allow 4 decimal places for such cases.
    In the same pricing procedure, we have two pricing condition types PR02 and ZR01.
    When PR02 is being used,it doesnt rounds off Price per unit.e.g .578888 = .578888
    But when ZR01 is being used the system rounds off price per unit.e.g.578888 = .58
    Please suggest where is the setting for it.
    Thanks
    Montee

    Hi,
    Which currency you are using? If its INR, then it will do only for 2 decimal places.
    The solution for ur problem can be ractified by changing the scales :
    Also check OSS 80183
    Thanks,
    Raja

  • Rounding off to two decimal places

    Hello,
    For simplicity, is there a method which will round off
    a double variable to two decimal places.
    Excample: if I have a result which equals 2.1999998
    and I want to display this as 2.20 in a TexTField.
    Any help would be much appreciated.
    Thanks

    If you are trying to do dollars and cents, I further recommend you use:NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance();
    String currencyOut = currencyFormatter.format(yourNumber);to format your numbers as they will give the correct precision for international currencies simply by setting the locale, and they will also automatically handle the currency symbols ($, DM FR, etc.)
    Doug

  • Rounding off to 2 decimal places

    Hi,
    I use "Double" for my calculations and since I am working with $$ ;-) I need to round it off at 2 decimal places. Any quick way to do this? or do I have to write some major code for that?
    Thanks

    This works for all the test cases. Try this
    import java.math.BigDecimal;
    import java.text.DecimalFormat;
    import java.text.NumberFormat;
    class RoundOff {
         public static void main(String args[]) {
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("173449.8"));
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("173449.98"));
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("-1.0"));
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("-1.0"));
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("-141.036"));
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("-00.1"));
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("-0.0"));
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("173449.98"));
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("173449.0.54"));
              //RARE EXCEPTIONS BUT WONT OCCUR
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("0125."));
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("0125.979.79E"));
              //RARE EXCEPTIONS BUT WONT OCCUR
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("173449.2354"));
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("173449.9874"));
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("173449.999"));
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("173449.999"));
         private static String formatPrecision(String s) {
              if (s == null || s.trim().length() == 0) {
                   return "0.00";
              try {
                   if (Double.parseDouble(s) == 0) {
                        return "0.00";
              catch (java.lang.NumberFormatException nfe) {               
                   return s;
              double d = 0.00;
              int ind = s.indexOf('.');
              String dec = "";
              if (ind > 0) {
                   dec = s.substring(ind);
                   if (dec.length() == 1) {
                        s = s.concat("00");
                        return s;
                   if (dec.length() == 2) {
                        s = s.concat("0");
                        return s;
                   if (dec.length() == 3) {
                        return s;
              if (ind == -1) {
                   return s.concat(".00");
              try {
                   d = Double.parseDouble(s);
                   BigDecimal bd = new BigDecimal(d);
                   bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP); //2 decimal places
                   d = bd.doubleValue();               
                   NumberFormat formatter = new DecimalFormat("0.00");
                   return String.valueOf(formatter.format(d));
              catch (java.lang.NumberFormatException nfe) {
                   return s;
    }

  • Rounding off to nearest whole number without condition

    hi,
    i want to round a real number to an integer value,,wihout any conditions like
    10.01 should be 11
    10.1 should be 11 and like that
    is it posible to do it?
    thanks in advance.
    amit

    It doesn't look like you are trying to round to the nearest whole number here. It looks like you are trying to find the smallest integer value that is greater than or equal to the real number. If so, you would want to use the CEIL function (i.e.
      1  SELECT CEIL(10.01)
      2*   FROM dual
    SCOTT @ hp92 Local> /
    CEIL(10.01)
             11Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Rounding off to nearest value with formatNumber

    Can I use the formatNumber tag to round my numeric value to the nearest value?
    Like if it's 15.7 I would like to display 16
    And if it's 15.2, I would like to display 15
    I could successfully truncate by giving a patteren but Im not sure if I can round it off.
    Regards,
    Leena

    Yes you can - the following works on JSTL 1.1 / Tomcat 5.5 :
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
    <html>
    <head><title></title></head>
    <body>
    Test Auto Rounding of 16.8 :
    <fmt:formatNumber value="16.88" pattern="##"/>
    <br/><br/>
    Test Auto Rounding of 16.2 :
    <fmt:formatNumber value="16.22" pattern="##"/>
    </body>
    </html>Message was edited by:
    appy77

  • Rounding off during APP (f110) of decimal point

    Hi
    Can any one help me? When I run the T.Code f110 for automatic payment programme is generate cheque propaly, here my client want to rounding off for the decimal point in cheque amount as if coin adjastment.

    Hello Arup,
    I guess OB90 is helpful to you so pls check the same.
    Thanks & Regards,
    Lakshmi S

  • Rounding off float to 2 decimal places and returning the float

    I tried doing bigdecimal but it doesnt work. :
    BigDecimal bd = new BigDecimal(5 * 0.0394);
              retval = bd.floatValue();
              System.out.printf(" th %f\n",retval);
    I see 0.197000. I know that there are 6 places since I didnt do %.2f. However its not the printf thats important . The float I want to return must be rounded off to two decimal places.
    Thanks in advance for the help,
    sb

    Use BigDecimal.round( MathContext mc ), where the MathContext object is set to a precision value of 3;
    BigDecimal roundedBigD = myOriginalBigD.round( new MathContext( 3 ) );� {�                                                                                                                                                                                                                                                                                                                                                                                                               

  • Rounding off the decimal place.

    how to round off to 2 decimal place for this following programs:
    double x;
    x = 5.0/3.0;
    System.out.println(x);
    answer for x is 1.6666666666666
    my desired output is 1.67

    import java.text.*;
    public class Foo {
        public static void main(String[] args) {
            double x;
            x = 5.0 / 3.0;
            DecimalFormat df = new DecimalFormat("0.##");
            System.out.println(df.format(x));
    }

  • How to round off quantity in inventory

    Hi,
    How to avoid decimal places for PC(Piece) in the goods movement transactions..  I have given 0 decimal places in CUNI transaction. It is working properly for Production Order during Conrimation but it is not working in Inventory transactions like MIGO, MB1C,MB1A....
    for example When I enter Unint of entry In Alternate Unit say '10 KG'  System Automatically Caliculates quantity in base unit in decimal places say 115.012 PC based on the conversion factor defined in material master.
    My requiremet is the base unit quantity PC rounded off to nearest value in as 115 (PC).
    The same thing is working fine for production order.
    please suggest me how to do.
    Thanks,
    Shekar

    this all depends on your conversion rate enterd in material master.
    if 115.012 PC  equals 10 KG.
    what do you actually want the system to do,
    it would now that you would get 115.012
    you want it to be 115,
    this would then mean that you have to modify the entered quantity from 10 to 9something
    Is it that what oyu want?
    you certainly cannot have 115 PC and 10 KG if you dont change the conversion rate in your material master

  • Working With Prices/Decimal Points

    I've recently figured out how to perform calculations on values by assigning them to variables in a click function however I'm working with prices in my app and it seems difficult to get prices/decimal points to claculate properly. At the moment my app looks like this:-
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application
    xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
    <mx:Script>
    <![CDATA[
    private function getTotal():void{
    var addon1Int:int = parseInt(addon1.text);
    var addon1Float:Number = parseFloat(addon1.text);
    var addon1Number:Number = new Number(addon1.text);
    var addon2Int:int = parseInt(addon2.text);
    var addon2Float:Number = parseFloat(addon2.text);
    var addon2Number:Number = new Number(addon2.text);
    var addon3Int:int = parseInt(addon3.text);
    var addon3Float:Number = parseFloat(addon3.text);
    var addon3Number:Number = new Number(addon3.text);
    var addon4Int:int = parseInt(addon4.text);
    var addon4Float:Number = parseFloat(addon4.text);
    var addon4Number:Number = new Number(addon4.text);
    var addon5Int:int = parseInt(addon5.text);
    var addon5Float:Number = parseFloat(addon5.text);
    var addon5Number:Number = new Number(addon5.text);
    var quantityNumber:Number = new Number(quantity.value);
    total.data = (addon1Number + addon2Number + addon3Number + addon4Number + addon5Number) * (quantityNumber);
    ]]>
    </mx:Script>
    <mx:Text id="addon1" text="5.99"/>
    <mx:Text id="addon2" text="6.99"/>
    <mx:Text id="addon3" text="8.99"/>
    <mx:Text id="addon4" text="4.99"/>
    <mx:Text id="addon5" text="3.99"/>
    <mx:NumericStepper id="quantity"/>
    <mx:Button label="Button" click="getTotal();"/>
    <mx:Text id="total"/>
    </mx:Application>
    It works ok if the numbers in the text areas are whole numbers like 8 or 4 but if I use numbers like 02.99, 05.09 the result comes out a bit srange. For example the result of the numbers that I have in there now if I set the value to 2 in the numeric stepper is 61.900000000000006 when I know from using a real calculator it should be 61.9. Is there any way perhaps of rounding this code to the nearest decimal point so it appears as 61.90?
    Are there any good tutorials that any of you know of when working with prices/decimal points in flex?

    I've managed to find the solution for this - the currency formatter. If anyone's interested or has similar problems her's the code that solves it for me:-
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application
    xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
    <mx:Script>
    <![CDATA[
    import mx.formatters.NumberBaseRoundType;
    private function getTotal():void{
    var addon1Int:int = parseInt(addon1.text);
    var addon1Float:Number = parseFloat(addon1.text);
    var addon1Number:Number = new Number(addon1.text);
    var addon2Int:int = parseInt(addon2.text);
    var addon2Float:Number = parseFloat(addon2.text);
    var addon2Number:Number = new Number(addon2.text);
    var addon3Int:int = parseInt(addon3.text);
    var addon3Float:Number = parseFloat(addon3.text);
    var addon3Number:Number = new Number(addon3.text);
    var addon4Int:int = parseInt(addon4.text);
    var addon4Float:Number = parseFloat(addon4.text);
    var addon4Number:Number = new Number(addon4.text);
    var addon5Int:int = parseInt(addon5.text);
    var addon5Float:Number = parseFloat(addon5.text);
    var addon5Number:Number = new Number(addon5.text);
    var quantityNumber:Number = new Number(quantity.value);
    var total:Number = (addon1Number + addon2Number + addon3Number + addon4Number + addon5Number) * (quantityNumber);
    totalAmount.text=currencyFormatter.format(total);
    ]]>
    </mx:Script>
    <mx:CurrencyFormatter id="currencyFormatter" precision="2" rounding="none" decimalSeparatorTo="." thousandsSeparatorTo="," useThousandsSeparator="true" useNegativeSign="true" currencySymbol="£" alignSymbol="left"/>
    <mx:TextInput id="addon1" text="5.99"/>
    <mx:TextInput id="addon2" text="06.99"/>
    <mx:TextInput id="addon3" text="08.99"/>
    <mx:TextInput id="addon4" text="04.99"/>
    <mx:TextInput id="addon5" text="03.99"/>
    <mx:NumericStepper id="quantity"/>
    <mx:Button label="Button" click="getTotal();"/>
    <mx:Text id="totalAmount"/>
    </mx:Application>

  • Rounding-off difference in Line Item vs Invoice

    Can anyone help on how to correct the rounding-off difference in the amount per line item display vs the amount printed in the invoice?  In viewing the document, the line item has an amount of 187.09, meanwhile, when invoice was printed, the amount was 187.10.

    Hi
    Ask ABAPer to modify the format for the invoice amont number field not to round off to nearest value in invoice form.
    Regards
    Laxmiprasad

  • Excise Rounding off

    Hi,
    Anybody help me regarding following issue where to assign rounding off for excise duty (BED,Ecess,HEcess)
    Regards,
    vivek

    Hi,
    In your calculation schema maintain AltCTyp as 17 against these conditions.This will round off to nearest rupee.
    Dhruba

  • MIRO Round off value

    Hi,
    I need to Round off the value in MIRO. Example, we have Rs.1000/- as the price and tax as Rs.12.36/-, system should round off this 12.36 to Rs.13 and display the tax amount as Rs.13.
    Is this possible in Standards?
    If so , where do we need to make the settings?
    Please help.
    Thanks.

    Hi,
    Please refer the below links..
    MIRO-Rounding off
    Rounding in MIRO
    Rounding off MIRO for decimal
    Thanks.

Maybe you are looking for

  • How can I carry information from one page to another page???

    Hi, I have two different pages, and two different tables on them. Like city and house pages and tables. I wantto add new record in house tables which depends on city tables and they must on be different pages, I mean I cant use master detail tables o

  • Protect Mode with APP-M

    Hello, I have a problem with Adobe Reader XI Protect Mode. When we open a PDF document through the APP-V layer I have an Access Dennied: Look the LOG: [12:11/13:40:07] NtCreateFile: STATUS_ACCESS_DENIED [12:11/13:40:07] real path: \??\mailslot\Lilo17

  • Function returning string.  Data type question

    Hello all, Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production Our database has a parent record master_member_record_id & and children of those records member_record_id. I wrote a function which returns the master record for

  • Problem downloading Patch Set Oracle 10.2.0.5 from SAP Service Market Place

    As mentioned in SAP Note 871735: Oracle patch set 10.2.0.5 To navigate to the DVD download: 1. On the right-hand side under 'Software Download', select the relevant software variant: - Oracle 10.2 software (64-bit) - Oracle 10.2 software (32-bit) 2.

  • POR - Creation date_Release date

    I would like to see the difference between the date of creation of a Purchase Order Requisition and the date on which that POR has been released by the responsible with ME55. The Request Date is the date of creation, ok, but.... how can I get the Dat