Rounding off 2 decimal number

Hi,
How can i round up float number to two decimal number.
For example
Number is 45.987654532 then It should be rounded up to 45.98
Number is 45.987654546 then It should be rounded up to 45.99Appriciated sample souuce (If any)
Tanks in advance

You could have a look at String's format() method. The format strings are
described in detail here:
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Formatter.htmlpublic class Round {
    public static void main(String[] args) {
        double number = 45.987654546;
        String roundStr = String.format("%.2f", number);
            // Rounded is 45.99
        System.out.println("Rounded is " + roundStr);
            // The same thing
        System.out.printf("Rounded is %.2f%n",  number);
}Note: these methods generate rounded Strings from floating
point numbers. Also, they round to a string representing the "nearest"
number - your first example is a little hard to understand in this regard.

Similar Messages

  • Rounding a decimal number up

    I have a field where the final answer comes up as a decimal and the client wants the final answer for the employee to see to be a whole number, but he wants it rounded up, no matter what the decimal answer is. Is there a way to do that?

    The script could be something like:
    // Custom calculation script
    (function () {
        // Get the field values, as numbers
        var v1 = +getField("Average of scores").value;
        var v2 = +getField("Text 4").value;
        // Perform the calculation, round up to nearest integer, and set this field value
        event.value = Math.ceil(v1 * v2);
    For more information on the Math.ceil method, see: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Math/ceil

  • Rounding off decimal points

    hi,
    i have record with value 237.741343124473. when user enter 237.7413431244, the record should return. i am using round function but is not working the way i want. is there any other function which can be used to round of the decimal points

    How it is possible, because in my earlier reply i have added a same valued row in the test table and now when i am giving :
    SQL> SELECT * FROM TEST WHERE TRIM(to_char(TRUNC(A, 12),'999.999999999999'))='237.741343124473';
             A
    237.741343
    It is returning the row.  Now you question will be why it is not returning the whole value? so for that:
    SQL> SELECT to_char(a,'999.999999999999') FROM TEST WHERE TRIM(to_char(TRUNC(A, 12),'999.999999999999'))='237.741343124473';
    TO_CHAR(A,'999.99
    237.741343124473
    Means, you have to apply to_char function on the column.Play around to_char,trunc functions; you can get your desired output.
    Regards
    Girish Sharma

  • Round decimal number to two places

    trying to round a decimal number to two places i.e. 1.98999 should round to 1.99.
    -tried using math.round but it only rounds to nearest integer
    -tried using decimalformat class but that converts to string, and cast wont allow me to convert from string back to double
    *is there a round method that allows you to specify decimal places?
    *or is there an easy method to cast a string back to a double?
    any advice is appreciated:)

    coynerm wrote:
    trying to round a decimal number to two places i.e. 1.98999 should round to 1.99.Agree.
    -tried using math.round but it only rounds to nearest integerI advise against rounding in most newbie situations. Usually it's the display of the variable you want to change.
    -tried using decimalformat class but that converts to string, and cast wont allow me to convert from string back to doubleOf course cast won't allow you to convert back. If you wanted to do that you'd use Double.parseDouble(stringVar); But we don't know why you are doing all this converting in the first place.
    *is there a round method that allows you to specify decimal places?
    *or is there an easy method to cast a string back to a double?Advice: Forgetting all this fooha with rounding, what in essence are you trying to achieve? Why all of this number manipulation in the first place? It will affect what should be the best answer.

  • Whole number rounding off in bom

    is it possible not to round off whole numbers in the bom component quantity? for example, when i input the number 8.000, the system rounds it off to just 8.

    Hi,
    Please let know your unit of measurement.
    Goto CUNI set the Decimal places and decimal pl.routing = 3 for your unit .
    Now try with decimal places at BOM.
    If your unit is related to whole number like Nos, EA system will give warring message.
    Pradeep

  • Rounding off to 0.05 decimal

    Post Author: masto123
    CA Forum: General
    Hi there,
    I am tring to round off a field which is displayed in AUD currency as $23.43 to $23.45. I have tried the round function
    round(,0.05) but I get an error. Is there any other way.
    pls help.
    regards
    m

    Post Author: yangster
    CA Forum: General
    If its a numeric value either a simple field or a summed field you should simply be able to format the number field and apply custom formatting to change it to 2 decimal places.  If its a text field you can use totext(field, 2).but the problem with your formula is that the format is round(field, #places)# of places needs to be a whole number not a fractionround(field, 2)

  • Round off Double to 2 decimal places??

    Hi all the pro out there..
    anybody can tell me how to go about rounding off eg 5.9542 to 2 decimal places in java? i went to search in API Double class, no method that allow me to do that..
    is there any other way?
    pls advise thank you

    If the former, you can do it manually by multiplying by an appropriate number, casting to int, and then dividing by the same number.Although this won't always work.
    Suppose you want 1.125 --> 1.1
    1.125 --> 11.25 --> 11 --> 1.1 plus some epsilon, since 1.1 can't be represented exactly in base-2.Yes, I know that (I assume you knew I knew that). So, maybe the OP needs to use both methods in combination (and maybe use some rounding method [such as in the Math class] other than cast).

  • Rounding off to a variable value to 4 decimal values in sap script ouput

    Hi All,
    I have a value getting displayed in sap script output as 235.6789 i want to Round off this variable value to 4 decimal values!
    What is the formatting option need to be used & how!
    Thanks in advance.
    Thanks,
    Deep.

    Hi,
    1.In layout just call that variable, where you need like:
    &variable(.4)&.
    Just see these:
    &symbol(Z)&  Omit Leading Zeros 
    &symbol(S)&  Omit Leading Sign 
    &symbol(<)&  Display Leading Sign to the Left 
    &symbol(>)&  Display Leading Sign to the Right 
    &symbol(C)&  Compress Spaces 
    &symbol(.N)&  Display upto N decimal places 
    &symbol(T)&  Omit thousands separator 
    &symbol(R)&  Right justified 
    &symbol(I)&  Suppress output of the initial value
    Regards,
    If helpful reward with points(Don't forget).

  • 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

  • Web dynpro + adobe form decimal field round off

    hello all,
    I am now developing an application which is based on the SAP WebDynpro and Adobe form, but the application has an error, if one can help me to resolve the error, I will be very thankful.
    The error is as follows, for a decimal filed on the Adobe form which is binded to a deicmal attribute of Webdynpro, if I get the value of the decimal field using the programming code as "context.nodexx.getAttribute("xx")", the decimal value is rounded off (e.g., 2.4 is changed to 2.0, 2.7 is changed to 3.0).
    for example:In Web Dynpro,  A node name is  "TestNode" which has a  type of decimalattribute named "TestAttr" ,  in  adobe form  a decimal field  bind to the TestAttr . when i input 2.3  in  adobe form,  i  click the button with code:
    this.wdComponentAPI.getMessageManager.reportSuccess(this.wdContext.nodeTestNode.getTestAttr()+"");
    the rusult is  :     2.0
    if  i  input  the  value  2.5   the result  will be  3.0
    Thanks All !

    Hi,
    there is a special display pattern to check for null values:
    null{pattern}
    Example:
    null{'please enter a value'}
    But I don't know if WDJ is really sending a null value. You can combine this with alternatives using '|' to separate alternatives.
    Regards,
    Juergen

  • 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 a float to two decimal places

    I want to make a function where I shall pass a float and and integer.
    The float shall have to be rounded off to a value in the integer.
    Can anyone please suggest how to round off a float.
    E.g.: if the float is 12.56890 and I want to round it off to 2 decimal places, then it should be 12.57.
    Regards
    Hawker

    I didn't mention any datatypes like float, double.True, but that is what the question is about, so you weren't answering the question. For a change.
    As I mentioned, that was just a mathematical steps to round of the floating point value. (Not in any programming languages point of view).False. You didn't mention that at all.
    This is the code for that in java.So here you are mentioning datatypes and floats for the same piece of mathematics that you have already been told, with reasons, doesn't work in floating point.
    which seems to be working fine
    Seems to. What evidence do you have that the float actually got rounded? As opposed to got displayed as rounded? Which is not what the OP asked for.
    And of course all that code seems to do is round 0.01 to two decimal places, which again is not what the OP asked for.
    For any remaining fans of this 'technique', please explain the behaviour of the following code:
         public static void     main(String[] args)
              int     count = 0, errors = 0;
              for (double x = 0.0; x < 1; x += 0.0001)
                   count++;
                   double     d = x;
                   int     scale = 2;
                   double     factor = Math.pow(10, scale);
                   d = Math.round(d*factor)/factor;
                   if ((d % 0.01) != 0.0) // if 'd' really has been rounded this should be zero
                        System.out.println(d % 0.01);
                        errors++;
              System.out.println(count+" trials "+errors+" errors");
         }

  • 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

  • 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 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 ) );� {�                                                                                                                                                                                                                                                                                                                                                                                                               

Maybe you are looking for

  • Sort the list of Favorite Servers, in the Connect to Server window?

    Hello... In 10.5 and 10.6, can I change the order of the Favorite Servers list in the Connect to Server window? I see the data is stored as files in ~/Library/Favorites, but I'm not seeing where the Connect to Server window gets its sort order. TIA

  • Gallery sharing on 808

    It seems that facebook/twitter sharing doesn't work from the gallery. Is there something that can be done to get it working?

  • DSL - Westell 7500 Gateway - PLEASE HELP!

    I recently moved my DSL service from one house to another and had my service upgraded from 1 to 3 mbps. I ordered a new modem (Westell 7500 Gateway) as well. I am unable to connect to the internet. I connected the new modem, the lights are all correc

  • HsGetValue - PowerPoint

    Hi, I am trying to using the HsGetValue function in PowerPoint. In excel I use following formula: ='H:\Oracle\SmartView\Bin\HsTbar.xla'!HsGetValue("Scenario#"&E$1&";Year#"&E$2&";Period#"&E$3&";View#"&E$4&";Entity#"&$A231&";Value#"&$A$7&";Account#"&E$

  • Unable to tie the location to a customer for internal requisitions

    Hello I am trying to test internal requisitions on my test server 10.2.0.2.0 and 12.0.6 are the version we reside on We have one operating unit and several organizations lying under this OU First Question Can I make an internal requistion in which so