How to round numbers

assume variable a is 4.647 and i want to convert this to 4.5 . how can i round numbers like this. Is there is a predefined method in java to achive this.

I don't think java.lang.Math.round() will do what the original post asked for, since it rounds to the nearest long number. So you still would have to write your own method to round 4.647 down to 4.5.

Similar Messages

  • How to round numbers using javascript in Adobe Acrobat Pro?

    How to round numbers using java script in Adobe Acrobat Pro?
    For example:
    1.2 becomes 1.0
    1.7 becomes 2.0
    Thank you.

    Assuming you've already set the field to a Number format category and limited it to one digit to the right of the decimal, you can use the following custom Validate script:
    // Custom Validate script
    event.value = Math.round(event.value);
    More info: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/roun d

  • How to round numbers in java?

    hey everyone. just wondering how i can round my final answer which is "repayment" located on the last line to the nearest whole value. thanks :) this is my code:
    //Conversion and Calculation
    principle = reader.readDouble("Enter Loan Amount: ");
    interestRate = reader.readDouble("Enter YEARLY interest rate: ");
    convertedRate = interestRate / 100;
    monthlyRate = convertedRate / 12;
    timePeriod = reader.readDouble("Enter the number of years for the repayment: ");
    convertedPeriod = timePeriod * 12;
    //Calculation Monthly Repayment Amount for a fixed number of years
    topHalf = Math.pow((1+monthlyRate),convertedPeriod);
    bottomHalf = (Math.pow((1+monthlyRate),convertedPeriod)-1);
    fraction = topHalf / bottomHalf;
    repayment = principle * monthlyRate * fraction;
    writer.println ("Fixed Monthly Repayment Amount = $" +repayment);                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Good point: Klue2k, don't forget about the negative
    case.Yes, never forget about the negative case. Your
    solution doesn't work with negative numbers!
    And by the way, if you had a little bit more of the
    good old klue2k, you wouldn't be embarassing yourself
    in this way.I think you're confusing me with somebody who give a 5h!t.

  • How to round numbers in RTF templates?

    Hello!
    I'm using BI Publisher for Word (Oracle BI Publisher Builder for Word 10.1.3.4.1) to build a template to my BI Publisher report and I want to calculate this:
    avg(X)/(avg(Y)-avg(Z)/0.9)
    The result should be rounded to 3 places.
    I tried:
    <?(sum(X) div count(X)) div ((sum(Y) div count(Y)) - (sum(Z) div count(Z)) div 0.9)?>
    and I obtained the expected result.
    But, when I try to round in this way:
    <?xdofx:round((sum(X) div count(X)) div ((sum(Y) div count(Y))-(sum(Z) div count(Z)) div 0.9),3)?>
    I obtain 0 when is expected other value.
    Can someone help me?

    Hi ,
    You can select the number format in RTF template .Double click the Form Field select
    Type :Number
    Number Format :#,##0.000
    Thanks.

  • How to round numbers to the nearest .25

    I would like to enter a number in one field and have it rounded to the nearest .25 in another column - (whether that's rounding up or down)
    Example:
    Actual Size
    Adjusted Size
    7.21435
    7.25
    Any help would be appreciated.
    Thanks!

    Hi c,
    The ROUND function limits the precision choices to powers of 10, so we need to work within that limitation:
    Multiply by four, round to the nearer whole number, divide by four.
    Formula in column B: =ROUND(A*4,0)/4
    All cells in B are formatted as Number, with decimal places set to 2.
    Regards,
    Barry

  • How to round the fractional values in Abap webdynpro?

    Hi Experts,
    I have designed a screen in which I have a field called ANZHL(which is numberic field of infotype14) It is a fractional digits which needs to be rounded when it comes to display in my webdynpro application?
    Here is my code .........
    How to round the ANZHL field ?
    **if start and end dates are changed then delete the old and insert the new else just mmodify the record
        if ws_0014_temp-begda ne ws_edit-begda or ws_0014_temp-endda ne ws_edit-endda.
          call function 'HR_INFOTYPE_OPERATION'
            exporting
              infty         = '0014'
              number        = wd_this->w_pernr
              subtype       = ws_0014_temp-subty
              objectid      = ws_0014_temp-objps
              lockindicator = ws_0014_temp-sprps
              validityend   = ws_0014_temp-endda
              validitybegin = ws_0014_temp-begda
              recordnumber  = ws_0014_temp-seqnr
              record        = ws_0014_temp
              operation     = 'DEL'
              nocommit      = 'X'
            importing
              return        = w_bapireturn.
          " key                    = w_bapireturn.
          if w_bapireturn-type ca 'EA'.
            r_bapireturn = w_bapireturn.
            return.
          endif.
          ws_0014 = ws_0014_temp.
          ws_0014-endda = ws_edit-endda.
          ws_0014-begda = ws_edit-begda.
          ws_0014-anzhl = ws_edit-anzhl.
                      call function 'HR_INFOTYPE_OPERATION'
            exporting
              infty         = '0014'
              number        = wd_this->w_pernr
              subtype       = ws_0014-subty
              objectid      = ws_0014-objps
              lockindicator = ws_0014-sprps
              validityend   = ws_0014-endda
              validitybegin = ws_0014-begda
              recordnumber  = ws_0014-seqnr
              record        = ws_0014
              operation     = 'INSS'
              nocommit      = 'X'
            importing
              return        = w_bapireturn.
          " key                    = w_bapireturn.
          if w_bapireturn-type ca 'EA'.
            r_bapireturn = w_bapireturn.
            return.
          endif.
        else.
          ws_0014 = ws_0014_temp.
          ws_0014-anzhl = ws_edit-anzhl.
    Edited by: Dharani us on Oct 8, 2009 10:15 AM

    Hi,
    For that attribute, you want to display the decimal values or what.
    Regards,
    Lekha.

  • How to store numbers in a stack....

    hello guys...i ve got the following assignment:
    Write a Java program that reads and evaluates a fully parenthesised arithmetic expression. The
    purpose of this program is to illustrate a fundamental use of stacks. Implement the stack using
    Linked Lists as explained in your notes.
    For e.g if a user enters the expression: (((6 + 9) / 3) * (6 � 4))
    The result should be 10.
    Your program should be properly documented and well structured. Specifications should be
    clearly written in your logbook for all the methods, constructors, and classes that you implement
    in the following format:
    Class / Method/ Constructor name explaining what it does
    Parameters
    Preconditions
    Postconditions
    Throws
    Now, i ve come up with the following code:
    import java.util.EmptyStackException;
    class StackNode {
         private static Object data;
         private StackNode link;
         private static StackNode head;
         private int totalnodes;
    // the constructors
    public StackNode(Object obj, StackNode lk)
         data = obj;
         link = lk;
    public StackNode()
         head = null;
         totalnodes = 0;
         // the push method
         public void push(Object obj)
              head = new StackNode(obj, head);
              totalnodes++;
         // the pop method
         public Object pop()
              Object answer;
              if(head == null)
                   throw new EmptyStackException();
              answer = head.getData();
              head = head.getLink();
              totalnodes--;
              return answer;
         // the isEmpty method
         public boolean isEmpty()
              return (head == null);
         // get data
         public Object getData()
              return data;
         // get link
         public StackNode getLink()
              return link;
         // size or length method
         public int size()
              return totalnodes;
         public static void main (String args [])
              int i;
              StackNode number = new StackNode();
              StackNode operator = new StackNode();
              head = new StackNode(data, head);
              number.push(new Integer(9));
              number.push(new Integer(6));
              operator.push(new Character('+'));
    and i dont know how to store numbers into the stack and how to use the operations such as addition substraction division and multiply...
    any ideas how to do that??
    cheers....

    This doesn't use a stack but the concept is the same:
    import java.util.*;
    public class formula {
    public  int aValue = 1;
    public  int bValue = 2;
    public  int cValue = 3;
    public formula() {
       //StringTokenizer st = new StringTokenizer("a + b/c", " abc()+-*/", true);
       //while (st.hasMoreTokens()) { System.out.println(st.nextToken()); }
       StringTokenizer st2 = new StringTokenizer("a + (c - b) + (b * c)", " abc()+-*/", true);
      int operand1 = 0;
      int operand2 = 0;
      int operator = 0;
      //flag: first operand has a value
      boolean firstOperandFull = false;
      //flag: second operand has a value
      boolean secondOperandFull = false;
      //flag: tokens are between parens
      boolean inParens = false;
      Vector inParensVector = null;
      MAINLOOP:
        while (st2.hasMoreTokens()) {
                  String x = st2.nextToken();
                  //if token is a blank skip it.
                  if (x.equals(" ")) { continue MAINLOOP; }
                  System.out.println(x);
                  //if token is open parens set flag and skip to next token
                  if (x.equals("(")) { inParens = true; inParensVector = new Vector(); continue MAINLOOP; }
                  //if tokn is close parens, retrieve the value from between the parens and reset flag.
                  if (x.equals(")")) { if (! firstOperandFull) { operand1 = doInParens(inParensVector); firstOperandFull = true; }
                                       else { operand2 = doInParens(inParensVector); secondOperandFull = true;  }
                                       inParensVector = null; inParens = false; }
                  //if token is open parens store all tokens until close else process the token
                  if (inParens) { inParensVector.add(x); }
                  else {
                       //if token is a variable put correct value in operand
                       if (x.equals("a")) { if (! firstOperandFull) { operand1 = aValue; firstOperandFull = true; }
                                            else { operand2 = aValue; secondOperandFull = true;  } }
                       if (x.equals("b")) { if (! firstOperandFull) { operand1 = bValue; firstOperandFull = true; }
                                            else { operand2 = bValue; secondOperandFull = true;  } }
                       if (x.equals("c")) { if (! firstOperandFull) { operand1 = cValue; firstOperandFull = true; }
                                            else { operand2 = cValue; secondOperandFull = true;  } }
                       //if token is a operator store the operation
                       if (x.equals("+")) { if (firstOperandFull) { operator = 1; } }
                       if (x.equals("-")) { if (firstOperandFull) { operator = 2; } }
                       if (x.equals("*")) { if (firstOperandFull) { operator = 3; } }
                       if (x.equals("/")) { if (firstOperandFull) { operator = 4; } }
                       System.out.println("operand1 = " + operand1 + " operand2 = " + operand2 + " operator = " + operator);
                        //if second operand has a value perform the operation.
                       if (secondOperandFull) {
                                               switch (operator) {
                                                        case 1 : operand1 = add(operand1, operand2); secondOperandFull = false; break;
                                                        case 2 : operand1 = subtract(operand1, operand2); secondOperandFull = false; break;
                                                        case 3 : operand1 = multiply(operand1, operand2); secondOperandFull = false; break;
                                                        case 4 : operand1 = divide(operand1, operand2); secondOperandFull = false; break;
                                                        }//end switch
                                                 } //end if
                     } //End inParens else
      } //End while
    System.out.println("answer = " + operand1);
    public static void main(String[] args) { //formula f = new formula();
    Vector v = new Vector();
    StringTokenizer st = new StringTokenizer(",Greg,,Paul,,", ",", true);
    String token = null;
    String lastToken = " ";
    boolean firstToken = true;
    while (st.hasMoreTokens()) {
    token = st.nextToken();
    if (firstToken) { if (token.equals(",")) { v.add("X"); }
    firstToken = false; }
    if (! token.equals(",")) { v.add(token); }
    else { if (lastToken.equals(",")) { v.add("X"); } }
    lastToken = token;
    } //End While
    if (token.equals(",")) { v.add("X"); }
    Enumeration tokens = v.elements();
    while (tokens.hasMoreElements()) {
          System.out.println((String)tokens.nextElement()); }
    } //End Main
    public int add(int operand1, int operand2) { return operand1 + operand2; }
    public int subtract(int operand1, int operand2) { return operand1 - operand2; }
    public int divide(int operand1, int operand2) { return operand1 / operand2; }
    public int multiply(int operand1, int operand2) { return operand1 * operand2; }
    public int doInParens(Vector inParensVector) {
          int operand1 = 0;
          int operand2 = 0;
          int operator = 0;
          boolean firstOperandFull = false;
          boolean secondOperandFull = false;
          Enumeration tokens = inParensVector.elements();
          INPARENSLOOP:
               while (tokens.hasMoreElements()) {
                  String x = (String)tokens.nextElement();
                  //if token is a blank skip it.
                  if (x.equals(" ")) { continue INPARENSLOOP; }
                  System.out.println("inparens : " + x);
                  //if token is a variable put correct value in operand
                      if (x.equals("a")) { if (! firstOperandFull) { operand1 = aValue; firstOperandFull = true; }
                                          else { operand2 = aValue; secondOperandFull = true;  } }
                  if (x.equals("b")) { if (! firstOperandFull) { operand1 = bValue; firstOperandFull = true; }
                                      else { operand2 = bValue; secondOperandFull = true;  } }
                  if (x.equals("c")) { if (! firstOperandFull) { operand1 = cValue; firstOperandFull = true; }
                                           else { operand2 = cValue; secondOperandFull = true;  } }
                 //if token is a operator store the operation
                 if (x.equals("+")) { if (firstOperandFull) { operator = 1; } }
                  if (x.equals("-")) { if (firstOperandFull) { operator = 2; } }
                 if (x.equals("*")) { if (firstOperandFull) { operator = 3; } }
                 if (x.equals("/")) { if (firstOperandFull) { operator = 4; } }
                  System.out.println("Inparens : operand1 = " + operand1 + " operand2 = " + operand2 + " operator = " + operator);
                 if (secondOperandFull) {
                                         switch (operator) {
                                                   case 1 : operand1 = add(operand1, operand2); secondOperandFull = false; break;
                                                       case 2 : operand1 = subtract(operand1, operand2); secondOperandFull = false; break;
                                                       case 3 : operand1 = multiply(operand1, operand2); secondOperandFull = false; break;
                                                       case 4 : operand1 = divide(operand1, operand2); secondOperandFull = false; break;
                                                       }//end switch
                                         } //end if
                  } //End while
               System.out.println("Inparens return = " + operand1);
               return  operand1;
    }//End doInParens
    }//End Class

  • How To See Numbers In Arabic Instead Of Indian Format

    I want to see numbers in Arabic format not in Indian format when i log on the Arabic Interface .
    I have EBS (12.0.6) installed on Linux centos , I have implement the below Oracle Metalink Note to solve this issue
    How To See Numbers In Arabic Instead Of Indian Format [ID 785243.1]
    I installed all the patched mentioned in the note (Apply forms version 10.1.2.2.0 with the forms patch 7488328 , Apply patch 7207440:R12.TXK.A , Apply patch 7601624 - NEW PROFILE OPTION: FORMS DIGIT SUBSTITUTION)
    These patches add the Profile option (FORMS DIGIT SUBSTITUTION) , but when i try to used it has no effect at all .
    So kindly if you have any idea about this issue please help me.
    Regards
    Fadi Lafi

    Hi,
    These patches add the Profile option (FORMS DIGIT SUBSTITUTION) , but when i try to used it has no effect at all .At what level you have set this profile option?
    So kindly if you have any idea about this issue please help me.Have you bounced the application services after setting this profile option? If not, please do so, login again and see if it works.
    Thanks,
    Hussein

  • How to assign numbers in external number range?

    Dear experts,
    Since NUMBER_GET_NEXT can only be used to assign numbers in internal number range, how to assign numbers in external number range?
    So far, I only know the NUMBER_CHECK function module to deal with external number ranges and it only check a number whether it lies in any external number range or not, but it doesn't update any number range status. What I need is a function module like NUMBER_GET_NEXT that supports external number range.
    Thanks in advance.
    Regards,
    Haris
    Edited by: harissahlan on Oct 19, 2011 5:44 AM

    With external number range, there is no updating of the number range objectt. The only thing you need to know is whether the number you wish to assign is allowed according to the external number range. And also check if there isn't already an object/document with the same number in the database.

  • How to make numbers in message text input  fields left aligned?

    Hi Friends
    I have completed one of my task .but getting result right side of the field.
    how to make numbers in message text input  fields left aligned?
    Thanks
    Aravinda

    Hi ,
    Sorry for late replay i am trying this alos not set that page....
    pageContext.forwardImmediatelyToCurrentPage(null, true, null);
    and one more that kff field working is fine for ex display any text pled displayed properly and only problem is not set the value and HrSitKeyFlex6 and HrSitKeyFlex7 fields are perfectly get the values but not pront HrSitKeyFlex8 that only my issue....
    Regards,
    Srini

  • How to enter numbers in Arabic?

    Hi All,
    How to write numbers in arabic?
    (how will you in normal papers....assume 123 to be in the arabic numerals here).
    Should it be:
    | -123|
    (or)
    | 123-|
    Thanks,
    Jana

    I won't say I am very clear about this topic. But I will give an example, which seems to show that number (in the double type) is logically of the form -000.00 while locale spacific String object can be both of the forms "000.00-" and "-000.00"
    // you can show the string below (formatted) on a JLabel with the following
    //<JLabel_instance>.setFont(new Font("Lucida Sans", Font.PLAIN, 22));
    NumberFormat nf = NumberFormat.getInstance(new java.util.Locale("ar","EG"));
    //NumberFormat nf = NumberFormat.getInstance(new java.util.Locale("fr","Fr"));   // compare
    DecimalFormat df=null;
    DecimalFormatSymbols dfs= null;
      if (nf instanceof DecimalFormat) {
          df = (DecimalFormat)nf;
          dfs = df.getDecimalFormatSymbols();
          dfs.setZeroDigit('\u0660');// set the beginning of the range to Arabic digits.. this can be commented out
          df.setDecimalFormatSymbols(dfs);
      String formatted = nf.format(-1234567.89);

  • How to write numbers in Arabic?

    Hi All,
    How to write numbers in arabic?
    (how will you in normal papers....assume 123 to be in the arabic numerals here).
    Should it be:
    | -123|
    (or)
    | 123-|
    Thanks,
    Jana

    Try the following.
    DecimalFormat formatter_ar=null;
    Numberformat form = NumberFormat.getNumberInstance(new Locale("ar","EG"));
    if(form instanceof DecimalFormat) formatter_ar = (DecimalFormat)form;
    String str = formatter_ar.format(-123.45);
    System.out.println(str);

  • How to rounding the cash discount at F110 payment program

    Dear All,
    Can you explain me, how to rounding off or rounding up to nearest rupee the cash discount at F110. In APP, the cash discount used to be calculated according to Payment term. But it is calculating decimal amounts also. But as per the business requirement, the cash discount should be deducted in rupees only. It should not be in decimals.
    Please remember, cash discount can not be edited at APP, because I have disabled the "Edit Proposal" option. I want the rounding the cash discount to be initiated through configuration only.
    Request you to help me out.
    Regards,
    Venkata Reddy

    Hi,
    maybe T-Code OB90 is helpful but I guess this setting is not only for cash discount.
    Best regards, Christian

  • How to save Numbers file as Excel (XLSX) file ?

    I just want to know how to save Numbers files into Excel format. Because other than Mac users can't able to access Numbers format.

    File, Export To, Excel…

  • I'm not sure I know how to use numbers 09 after iworks has left. I emailed a copy from my ipad to my pc, saved it  but, it won't open on my pc desktop.  Also, how do I move an excell spread sheet now from my pc to my ipad?

    I'm not sure I know how to use numbers 09 now that iworks has departed. I emailed a copy from my ipad to my pc,saved it to my desktop but it won't open. Also, how do I now move an excel spreadsheet from my pc to my ipad?

    iWork (no 's') for iOS & iWork for Mac have not gone away.
    iWork.com (beta) (also no 's') is going away the end of July. iWork.com (beta) is/was an online method of sharing iWork files with other users & never moved out of beta in 3+ years. It is a completely different entity than the iWork apps & is not & never has been necessary for the iWork apps to function.
    A Numbers document, as well as Pages or Keynote documents, cannot be opened on a PC. You must first export them to a file that a PC can use. For Numbers that is generally Excel. In Numbers on your iPad tap the wrench & then tap Share & Print & choose Excel as the file type.
    As for transfering a file from a PC to an iPad, I'm not sure as I don't use a PC.

Maybe you are looking for

  • [SOLVED] Trying to get samba to work, smbtree issues:

    I am having a bit of an issue getting my computer to show up to my Mint laptop.  Running smbtree as it stands right now produces this output: Enter mikeyd's password: WORKGROUP \\MINT mint server (Samba, LinuxMint) \\MINT\IPC$ IPC Service (mint serve

  • How to configure purchase requesition in third party order

    dear expert can you explain how to configure purchase requesition in third party order. vicky

  • Help with placing and altering jpg in Illustrator CS4

    I am trying to use a jpg file in my design.  it is an FDIC logo which is has the logo part in black and the background in white.  I need to invert the colors and change the background to be brown to match my illustrator file colors.  tracing is not a

  • Error in finding the phase and magnitude of the acquired signal

    Dear sir,               I am trying to develop a module for calculating  unbalance in the spindle . I am using an accelerometer and  tacho for that. Till the last part in my vi I am getting the output properly but in final stage while finding the pha

  • Using special symbols '|' in bookmarks

    One webpage I use a lot, after clicking some options, generates a URL with the  |  symbol.   When I bookmark the page, then go to show all bookmarks, the URL has been changed, replacing   |  with  %7C.  I can edit the stored URL, changing it back to