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

Similar Messages

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

  • Round off quantity variable eliminating decimal places

    Hi,
      I have a variable of quan type with value = 1008.123
      I want to round it off with no decimal to be displayed.
      Please suggest.

    Hi,
      Refer
    https://forums.sdn.sap.com/click.jspa?searchID=11055268&messageID=4565374
    https://forums.sdn.sap.com/click.jspa?searchID=11055268&messageID=4721312
    https://forums.sdn.sap.com/click.jspa?searchID=11055268&messageID=2700419
    Regards
    KIran

  • 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");
         }

  • To remove decimal places and round

    hi all ,
    select       (sum(case when (F.ITEM_UOM = 'Cubic Feet' and upper(substr(H.SLURRY_TYPE,1,3)) <> upper('Top')) then
                (((((H.SLURRY_VOL_ACTUAL * 5.6146)/H.SLURRY_YIELD)*94)/2000)   )
                 when (F.ITEM_UOM = 'Cubic Feet' and upper(substr(H.SLURRY_TYPE,1,3)) = upper('Top')) then
             (   ((nvl(H.CLASS_V_CEMENT,0)*94)/2000)   ) 
            when F.ITEM_UOM =  'Pound' then
          CEIL(  ROUND((((((H.SLURRY_VOL_ACTUAL * 5.6146)/DECODE(H.SLURRY_YIELD,0,NULL,H.SLURRY_YIELD)))*94)*F.ITEM_PERCENT/100)))/2000
           end)*(j.opn_value/2))  SUM_MAT_ACT_TON ,--------transport
                       sum(case when (F.ITEM_UOM = 'Cubic Feet' and upper(substr(H.SLURRY_TYPE,1,3)) <> upper('Top')) then
                ((H.SLURRY_VOL_ACTUAL * 5.6146)/H.SLURRY_YIELD)
          when (F.ITEM_UOM = 'Cubic Feet' and upper(substr(H.SLURRY_TYPE,1,3)) = upper('Top')) then
                nvl(H.CLASS_V_CEMENT,0)
            when F.ITEM_UOM =  'Pound' then
                ROUND(((ROUND(((H.SLURRY_VOL_ACTUAL * 5.6146)/DECODE(H.SLURRY_YIELD,0,NULL,H.SLURRY_YIELD)))*94)*F.ITEM_PERCENT/100 )/P.ATTRIBUTE5)
       end) SUM_sload ,    ----sload
       sum(case when (F.ITEM_UOM = 'Cubic Feet' and upper(substr(H.SLURRY_TYPE,1,3)) <> upper('Top')) then
                ((H.SLURRY_VOL_ACTUAL * 5.6146)/H.SLURRY_YIELD)
         -- when (F.ITEM_UOM = 'Cubic Feet' and upper(substr(H.SLURRY_TYPE,1,3)) = upper('Top')) then
              --  nvl(H.CLASS_V_CEMENT,0)
            when F.ITEM_UOM =  'Pound'  and F.BLEND <> 'PH'then
                ROUND(((ROUND(((H.SLURRY_VOL_ACTUAL * 5.6146)/DECODE(H.SLURRY_YIELD,0,NULL,H.SLURRY_YIELD)))*94)*F.ITEM_PERCENT/100 )/P.ATTRIBUTE5)
       end) BLENDING
      ,e.opn_job_desc
         FROM xxnp_opn_joblog_001 E,
              XXNP_OPN_JOBLOG_EST_002   F,
              XXNP_OPN_JOBLOG_STAGE_002 G,
              XXNP_OPN_JOBLOG_SLURRY_003 H,
        XXNP_OPN_JOBLOG_RES_005 J,
         MTL_SYSTEM_ITEMS_B P
          WHERE E.OPN_JOB_DESC   = 'K/D/SP158/SA399/1338/D/0510/1' AND
            E.MANUAL='N'
       and J.opn_resource_desc='4X4  PICK-UP OR LIGHT VEHICLES'
        AND E.OPN_JOBLOG_001_ID = J.OPN_JOBLOG_001_ID
         and F.INVENTORY_ITEM_ID=P.INVENTORY_ITEM_ID
           AND p.ORGANIZATION_ID='103'
          AND E.OPN_JOBLOG_001_ID = G.OPN_JOBLOG_001_ID
            AND G.OPN_JOBLOG_006_ID = H.OPN_JOBLOG_006_ID
            AND H.OPN_JOBLOG_007_ID = F.OPN_JOBLOG_007_ID
            AND G.OPN_JOBLOG_006_ID = H.OPN_JOBLOG_006_ID
            AND H.OPN_JOBLOG_007_ID = F.OPN_JOBLOG_007_ID
                                    GROUP BY E.OPN_JOB_DESC,j.opn_value
    o/p  i am getting
    SUM_MAT_ACT_TON      SUM_SLOAD                         BLENDING                                   OPN_JOB_DESC
    11587.7954154787         1957.62401925833               1454.62401925833                       K/D/SP158/SA399/1338/D/0510/1
    well can anyone guide me on  obtaining the following output (to remove decimal places and round )
    SUM_MAT_ACT_TON      SUM_SLOAD                         BLENDING                                   OPN_JOB_DESC
    11588                           1958                                      1455                                          K/D/SP158/SA399/1338/D/0510/1thanking in advance
    Edited by: makdutakdu on May 25, 2010 12:48 PM

    select      round( (sum(case when (F.ITEM_UOM = 'Cubic Feet' and upper(substr(H.SLURRY_TYPE,1,3))  upper('Top')) then
                (((((H.SLURRY_VOL_ACTUAL * 5.6146)/H.SLURRY_YIELD)*94)/2000)   )
                 when (F.ITEM_UOM = 'Cubic Feet' and upper(substr(H.SLURRY_TYPE,1,3)) = upper('Top')) then
             (   ((nvl(H.CLASS_V_CEMENT,0)*94)/2000)   ) 
            when F.ITEM_UOM =  'Pound' then
          CEIL(  ROUND((((((H.SLURRY_VOL_ACTUAL * 5.6146)/DECODE(H.SLURRY_YIELD,0,NULL,H.SLURRY_YIELD)))*94)*F.ITEM_PERCENT/100)))/2000
           end)*(j.opn_value/2)))  SUM_MAT_ACT_TON ,--------transport
                       round(sum(case when (F.ITEM_UOM = 'Cubic Feet' and upper(substr(H.SLURRY_TYPE,1,3))  upper('Top')) then
                ((H.SLURRY_VOL_ACTUAL * 5.6146)/H.SLURRY_YIELD)
          when (F.ITEM_UOM = 'Cubic Feet' and upper(substr(H.SLURRY_TYPE,1,3)) = upper('Top')) then
                nvl(H.CLASS_V_CEMENT,0)
            when F.ITEM_UOM =  'Pound' then
                ROUND(((ROUND(((H.SLURRY_VOL_ACTUAL * 5.6146)/DECODE(H.SLURRY_YIELD,0,NULL,H.SLURRY_YIELD)))*94)*F.ITEM_PERCENT/100 )/P.ATTRIBUTE5)
       end)) SUM_sload ,    ----sload
       round(sum(case when (F.ITEM_UOM = 'Cubic Feet' and upper(substr(H.SLURRY_TYPE,1,3))  upper('Top')) then
                ((H.SLURRY_VOL_ACTUAL * 5.6146)/H.SLURRY_YIELD)
         -- when (F.ITEM_UOM = 'Cubic Feet' and upper(substr(H.SLURRY_TYPE,1,3)) = upper('Top')) then
              --  nvl(H.CLASS_V_CEMENT,0)
            when F.ITEM_UOM =  'Pound'  and F.BLEND  'PH'then
                ROUND(((ROUND(((H.SLURRY_VOL_ACTUAL * 5.6146)/DECODE(H.SLURRY_YIELD,0,NULL,H.SLURRY_YIELD)))*94)*F.ITEM_PERCENT/100 )/P.ATTRIBUTE5)
       end)) BLENDING,
       e.opn_job_desc
         FROM xxnp_opn_joblog_001 E,
              XXNP_OPN_JOBLOG_EST_002   F,
              XXNP_OPN_JOBLOG_STAGE_002 G,
              XXNP_OPN_JOBLOG_SLURRY_003 H,
        XXNP_OPN_JOBLOG_RES_005 J,
         MTL_SYSTEM_ITEMS_B P
          WHERE E.OPN_JOB_DESC   = E.OPN_JOB_DESC  AND
            E.MANUAL='N'
       and J.opn_resource_desc='4X4  PICK-UP OR LIGHT VEHICLES'
        AND E.OPN_JOBLOG_001_ID = J.OPN_JOBLOG_001_ID
         and F.INVENTORY_ITEM_ID=P.INVENTORY_ITEM_ID
           AND p.ORGANIZATION_ID='103'
          AND E.OPN_JOBLOG_001_ID = G.OPN_JOBLOG_001_ID
            AND G.OPN_JOBLOG_006_ID = H.OPN_JOBLOG_006_ID
            AND H.OPN_JOBLOG_007_ID = F.OPN_JOBLOG_007_ID
            AND G.OPN_JOBLOG_006_ID = H.OPN_JOBLOG_006_ID
            AND H.OPN_JOBLOG_007_ID = F.OPN_JOBLOG_007_ID
                                    GROUP BY E.OPN_JOB_DESC,j.opn_value

  • Is it possible to convert a float to two decimal places

    Can anyone help me to convert a float to two decimal places
    float f=16;
    System.out.println(f);
    It will print 16.0
    But I want to get printed as 16.00

    "convert" no, as no conversion is needed, obviously. Format the output, yes. Read the API for String and its printf method.

  • Rounding a number to 2 decimal places

    Is there anyway using the Round function to get it to .2
    decimal places rather than the nearest whole figure...
    I have a table that contains product prices, some of these
    are already in a nice 2 decimal format (such as 7.99 or 12.49) but
    I also have some that are like this-43.990002 and this-8.9899998.
    What is the best way to round these to 2 decimal places?
    thanks

    Do some experimentation. If you are using numberformat you
    might not need to use round.

  • 0QUANTITY - Six decimal places - Rouding to the third decimal place

    Hello experts, how are you?
    We are facing a problem with decimal places here in the project.
    We're using M3 unit of measure and the user required 6 decimal places.
    We already changed ANDEC and DECAN fields from T006 table to value 6,
    the key figure itself (0QUANTITY), the key figure in the InfoCube and in the input-ready query, but the recorded data is being rounded to the third decimal place.
    Can someone help us with it?
    Thanks in advance,
    Helder Rios

    Hi,
    First of all I'd like to thank you for your help guys.
    Ashish, I changed the data element RSKYFQUA to 6 decimal places. But when I try to activate the cube, the system is not able to re-create the fact tables.
    Do you know if there's a solution for it?
    Thanks in advance,
    Helder Rios

  • I got an android, turned off my imessage on my iphone and deactivated the iphone through apple support but I still don't get messages from people using iphones.  What's wrong?

    I got an android, turned off my imessage on my iphone and deactivated the iphone through apple support but I still don't get messages from people using iphones.  What's wrong?

    Go ahead and call AppleCare at 1-800-692-7753 and ask them to revoked your certificate

  • Mutator to compute set and return the value

    Hi
    I am having trouble working out how to do a mutator that does all three
    compute a value set the value and then return it this is what i have so far
    this example calculates and returns the value but does it set the value of totalSlices ???? this is the best option so far
    public int totalSlices (){
    int total = meatSlices + vegSlices;
    return (int) total;
    this one seems more likely to me but unsure is this a set method as well
    public insert (int fiveC)
    fiveCentCoin += fiveC;
    returne fiveCentCoin;
    this is the final example i have come up with but dont know if it sets the value as well
    public int calculateCost () {
    double cost;
    if (age==0) {
    age = 0.1;
    if (neutered) {
    cost = (100/age) + (stay * 3) + SHOTS + TAGS;
    } else {
    cost = (100/age) + (stay * 3) + SHOTS + TAGS + NEUTER;
    return (int) Math.round (cost);
    the problem i face i am not sure of how to combine a mutator calculation, set method and return it all in one i havnt done that before and cannot find an example
    thanks

    I think you're trying to take a hollistic approach to programming. That won't work.
    You need to go back and get a good understanding of exactly what each element of Java does.
    Sylvia.

  • Loop through a csv file and return the number of rows in it?

    What would be simplest way to loop through a csv file and
    return the number of rows in it?
    <cffile action="read" file="#filename#" output="#csvstr#"
    >
    <LOOP THROUGH AND COUNT ROWS>

    ListLen(). Use chr(13) as your delimiter

  • SUBMIT and return the value of that report into internal table

    Dear all,
    I have a requirement. I want to submit a report and return the value of that report into my internal table.
    How to do this.
    Pl. guide.

    Hi Vidhya,
    Below links from SAP help will resolve your issue.
    http://help.sap.com/saphelp_nw04/Helpdata/EN/fc/eb3bde358411d1829f0000e829fbfe/content.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3bd1358411d1829f0000e829fbfe/content.htm
    Edited by: Harsh Bhalla on Jan 2, 2010 11:54 AM

  • My iCal won't go online and returns the error message: The server responded with "500" to operation CalDAVAccountRefreshQueueableOperation.

    My iCal won't go online and returns the error message: "The server responded with “500” to operation CalDAVAccountRefreshQueueableOperation."

    OK Now I can answer my own question.  The incomprehensible (inexcusably geeky) error message is actually Apple language for saying simply: "The iCloud servers are down again.  Please wait until we've fixed them."  I found this out by talking to Apple support.  It took about 12 hours for the iCloud server synching calendars to come back online.  When they did, my calendar reloaded, and everything was fine.

  • I have now transfered my files of ripped CD's to my iTunes library three times. On each occassion, the conversion seems to occur fine, the files play, but when I close my computer and return the next day, iTunes says it cannot locate any of those files.

    I have now transfered my files of ripped CD's to my iTunes library three times Since upgrading to iTunes 11 and Windows 8. On each occassion, the conversion seems to occur fine, the files play, but when I close my computer and return the next day, iTunes says it cannot locate any of those files. Three times. Beginning to lose my temper. Advice? Suggestions? Could the fact that my original library is located on a network drive have anything to do with it? Thanks for your help, all.

    Repair security permissions
    Right-click on your main iTunes folder and click Properties, then go to the Security tab and click Advanced. If necessary grant your account and system full control to this folder, subfolders and files, then tick the option to replace permissions on child objects which will repair permissions throughout the library. This is the XP dialog but Windows 7/8 shouldn't be too different.
    Repeat for the media folder if it isn't a subfolder of the iTunes folder.
    tt2

  • How to convert Smart Form into PDF format and return the result in BAPI?

    I want to convert a Smart Form into PDF format and return the result in BAPI.
    can anyone tell me how it can be done with related example
    regards
    pranay

    hi,
    smart form to pdf--
    All you have to do is call your SF to get OTF and then concert it to PDF. Works like charm:
    DATA: p_output_options TYPE ssfcompop,
    p_control_parameters TYPE ssfctrlop.
    p_control_parameters-no_dialog = 'X'.
    p_control_parameters-getotf = 'X'.
    CALL FUNCTION v_func_name "call your smartform
    EXPORTING
    output_options = p_output_options
    control_parameters = p_control_parameters
    IMPORTING
    job_output_info = s_job_output_info.
    call function 'CONVERT_OTF_2_PDF'
    tables
    otf = s_job_output_info-otfdata
    lines = t_pdf
    and if u need more u can check below links also
    Check the below links..
    Re: Smartforms to PDF
    Re: smartform (otf) as pdf and sending as email-attachment
    VISIT THIS LINK
    Re: Smartforms to PDF
    PLZ REWARD POINTS IF IT HELPS YOU
    rgds
    anver

Maybe you are looking for

  • March 2013 Month make my Calendar app to crash!

    Hi, When I am in Month view, and change to March, the app. Crash. If I am in year view and selects March it crash. If I use week preview no problem. I se this on iPad 2 (newest ios) and on a iPad 1. It is a iPad isue only! Regards Henrik

  • Applet/servlet communication for byte transmission

    Hello all ! I wrote an applet to transfer binary file from web servlet (running under Tomcat 5.5) to a client (it's a signed applet) but I have a problem of interpretation of byte during transmission. the code of the servlet is :         response.set

  • Pricing schema

    Dear All, In my import pricing procedure i have condition type PB00 & another condition type ZXYZ (this condition type is like PB00)...the need of this Z condition type is we need our CVD price to be calculated on the price user will enter against th

  • Programmatic creation of Oracle 10gAS Release 2 general mod_plsql DADs

    Hi Everyone, We use Oracle Application Server 10gAS version 10.1.2.3.0 and as part of our setup we create and use General type DADs. (Created within Enterprise Manager, under HTTP Server --> Administration tab --> PL/SQL Properties --> DADs. My quest

  • Less Outputs means no support for multiroom A/V users

    Currently using an AppleTV over a 12 room system that uses a 8x8 Component Matrix Switch for video and sends the sound via RCA audio to audio only rooms.....new AppleTV with HDMI only is a joke to the high end users....bad enough the original AppleTV