Rounding up numbers

Hi,
I would like to know how to round up number in jsp whether it is below 0.5 or above 0.5... my sample code:
double totalquantity=0;
int totalratio = 0;
long q = 0;
ratio = rs.getString("ratio");
q = totalquantity/totalratio * Integer.parseInt(ratio);
thank you

you are getting the double through the expression mentioned
q = totalquantity/totalratio * Integer.parseInt(ratio);
and assigning that to long, without casting.
Hence the problem-Loss Of Precision.Make the q as double,use Math.round() on that depending on u r requirement.

Similar Messages

  • Rounding UP numbers in pl\sql

    Hi is there a way to round up numbers in pl\sql?

    Maybe you are looking for CEIL.
    with testdata as (select level/3-2 num from dual connect by level<=15)
    select num, round(num), ceil(num)
    from testdata;
    NUM    ROUND   CEIL
    -1,67     -2     -1
    -1,33     -1     -1
    -1     -1     -1
    -0,67     -1     0
    -0,33     0     0
    0     0     0
    0,33     0     1
    0,67     1     1
    1     1     1
    1,33     1     2
    1,67     2     2
    2     2     2
    2,33     2     3
    2,67     3     3
    3     3     3

  • ETEXT output truncating/rounding large numbers

    I have an eTEXT template that includes the definition:
    <FORMAT>     <DATA>
    NUMBER BankAccount/BankAccountNumber
    When a large number is encountered the output appears truncated/rounded. For example; the account number 444470301880513641 is output as 444470301880513660.
    Data:
    <BankAccountNumber>444470301880513641</BankAccountNumber>
    Output:
    ...#444470301880513660#....
    Other than convert the FORMAT to an Alpha are there any known tips or tricks to correct this scenario?
    Regards
    Edited by: bdansie on 10-Jan-2012 17:44

    Hi Tom, Thanks for the reply. I am reading a hex value in from a serial port. the number is large and when i format it as hex on one chan it is off by a small amount. there is some rounding in the LSD. i then take another reading later and calculate the delta. since i dont have the right values to begin with my difference calculation is wrong. when i read as bytes through 8 channels, i can see the ascii for each digit and that they are correctly displayed. using a formula module i can convert from ascii to decimal so that i get the decimal equivalent of the hex character then in the next formula i do the math to find the value of each hex digit in place it holds. then using a sum arithmetic module i get the final value of the large number coming in. it is correct all the way upto the aritmetic sum. i tried cutting the large hex number into two parts and then adding up the weighted parts and still have the wrong ans in the display module. i also tried dividing the halves by 1000 prior to adding them so that i was working with smaller numbers in the summation but that didnt help.
    so i did the math directly in the extended portion of the variables. the numbers add up properly there but when i try to bring the correct sum back into the work sheet to display it, it is wrong again. it seems that a value around 04000000 hex is the limit. below that i get the right value displayed that was calculated in the variable field, above it there is some degree of variation. I can set the limit of cycles to a value below where the addition becomes problematic or i can export the hex to a spreadsheet, do the math there and then bring it back in but i will still have the same issue displaying the answer.
    the limitation doesnt seem to be in DASYLab in general but in the Read, Formula, Constant Generator modules that read the variable back into the worksheet. it is displayed properly in the contents window

  • Pages rounding up numbers in a .doc file to 2 decimal places

    Hello, I have a problem, with Pages (3.4) on OS 10.7.5...
    When I go to open a .Doc file, Pages seems to round up some numbers to 2 decimal places. I did find another thread which dealt with this problem inside of Tables, but I am not using tables in this document.... another problem is that the new rounded up number is not editable in Pages once the document is open. e.g.
    In word/open office I see the figure (which is in fact a series of dates - i did not write this document btw)
         12.12.24.1.13
    in Pages is only see
         .13
    and this .13 is totaly un-editable and unselectable.
    Can you help ?

    Got it!
    I tried opening it in TextEdit but the funky dates were omitted from the page. Then I opened it in LibreOffice and it looked OK. The problematic dates seemed created by a special Word function. The behaving dates were manually written.
    I selected all content of the document in LibreOffice and pasted into a Pages document and all dates came out as they should.

  • Rounding decimal numbers in the planning book

    Hi,
    Is there any way to round up the decimal numbers shown in the forecast/inventory/DRP planning book of SPP ?
    Thanks and Regards
    Mitesh

    Hi Mitesh,
    Please go to SPRO:
    APO -> Supply Chain Planning -> SPP -> Settings for user interfaces -> Assign Key Figures
    Go to "Semantic Maintenance"
    Set "Decimal Places" Column to Zero for all key figures.
    Regards,
    Aapka Mukundan

  • Rounding of Numbers

    Hi, can somebody tell me why the following generates this output it looks like ROUND_HALF_EVEN but should round up always.
    import java.math.BigDecimal;
    public class TestDecimal {
         public static void main(String[] args) {
              System.out.println(new BigDecimal(1.45).setScale(1,BigDecimal.ROUND_HALF_UP).doubleValue());
              System.out.println(new BigDecimal(1.55).setScale(1,BigDecimal.ROUND_HALF_UP).doubleValue());
              System.out.println(new BigDecimal(1.65).setScale(1,BigDecimal.ROUND_HALF_UP).doubleValue());
    }1.4 => Should be 1.5
    1.6 => Should be 1.6
    1.6 => should be 1.7
    Am I completely mistaken? This is java-1.5. How can I achive what I want rounding up starting with >= 0.5 like we learned in school and is documented in javadoc of ROUND_HALF_UP.

    System.out.println("1.44 => 1.4 => " + new BigDecimal(1.44).setScale(1,RoundingMode.HALF_UP).doubleValue());
    System.out.println("1.45 => 1.5 => " + new BigDecimal(1.45).setScale(1,RoundingMode.HALF_UP).doubleValue());
    System.out.println("1.54 => 1.5 => " + new BigDecimal(1.54).setScale(1,RoundingMode.HALF_UP).doubleValue());
    System.out.println("1.55 => 1.6 => " + new BigDecimal(1.55).setScale(1,RoundingMode.HALF_UP).doubleValue());
    System.out.println("1.64 => 1.6 => " + new BigDecimal(1.64).setScale(1,RoundingMode.HALF_UP).doubleValue());
    System.out.println("1.65 => 1.7 => " + new BigDecimal(1.65).setScale(1,RoundingMode.HALF_UP).doubleValue());Produces:
    1.44 => 1.4 => 1.4
    1.45 => 1.5 => 1.4
    1.54 => 1.5 => 1.5
    1.55 => 1.6 => 1.6
    1.64 => 1.6 => 1.6
    1.65 => 1.7 => 1.6
    The same result is with:
    MathContext context = new MathContext(2,RoundingMode.HALF_UP);
    new BigDecimal(1.44).round(context).doubleValue();

  • Adobe Reader XI - How do i stop numbers being rounded up on forms

    Hi,
    I am using the Adobe Reader XI, with regards to filing in figures on forms that I use. The form keeps on rounding up numbers. For example if I type in 2.5 and go to the next box on the form, the figure will immediately change to 3. It is extremely frustrating and in my line of work the figures have to be exact. Please can anyone help and advise if there is anything I can do or settings that I can change to be able to keep numbers on the form with decimal points showing without them being rounded up.
    Thanks

    To emphasise: this happens only if the designer of the form decides to not allow any decimal places.

  • Comparison error while trying to round like Excel

    I have two different but related issues. First: my LabVIEW application is not passing my client's validation because the results in LabVIEW are not exactly the same as the ones my client get when using MS Excel. The problem is with rounding: LabVIEW and Excel round numbers differently and (unfortunatelly) I must round the numbers the Excel way.
    Because I need to round after the decimal point, I started using a nice VI I found here at ni.com called "DecimalRoundingLV8.5vi". However, because of the difference between LabVIEW and Excel, I can't use that VI as is. For example, rounding to the third place after the decimal point:
    Number to round
    LABVIEW
    EXCEL
    0.0045
    0.0040
    0.0050
    So, my first issue is that one, I need to round like Excel... however, the solution I implemented brought up a weird issue and I am not sure if I am witnessing a bug in LabVIEW.
    I modified the decimal rounding VI. Below is an image of the code and I am also attaching it:
    First, if the number is negative I am changing it to positive to round. At the end I return the sign.
    Like the original VI, I multiply the number to round times 10^x, where x is the place after the decimal point I want to round to, I do the rounding and then divide the result by 10^x.
    However, I also multiply the number to round times 10^(x+1) and divide the result by 10 to get the unit as the reminder and to evaluate that number. If the number is less than 5, I round as usual; if not, round toward +infinity.
    So far, so good and everything seems to be fantastic. But when I tested this code I found the following weird scenario. For example, rounding to the third place after the decimal point:
    Number to round
    LABVIEW
    EXCEL
    0.0855
    0.0860
    0.0860
    0.0856
    0.0860
    0.0860
    0.0857
    0.0860
    0.0860
    0.0858
    0.0860
    0.0860
    0.0859
    0.0860
    0.0860
    0.0860
    0.0860
    0.0860
    0.0861
    0.0860
    0.0860
    0.0862
    0.0860
    0.0860
    0.0863
    0.0860
    0.0860
    0.0864
    0.0860
    0.0860
    0.0865
    0.0860
    0.0870
    0.0866
    0.0870
    0.0870
    0.0867
    0.0870
    0.0870
    0.0868
    0.0870
    0.0870
    0.0869
    0.0870
    0.0870
    0.0870
    0.0870
    0.0870
    0.0871
    0.0870
    0.0870
    0.0872
    0.0870
    0.0870
    0.0873
    0.0870
    0.0870
    0.0874
    0.0870
    0.0870
    0.0875
    0.0880
    0.0880
    Note when rounding 0.0865. LabVIEW got it wrong! However, LabVIEW did not got it wrong for 0.0855 or 0.0875. When I ran the code using the highlight feature, it turns out the problem was the comparison function. It is literally saying that 5<5 is true.
    I tested this in LabVIEW 8.2 and LabVIEW 12. I am using Windows XP SP3.
    These numbers are not the only cases with this weird behavior. Other numbers are 0.1425, 0.1725, 0.1745, and more. I don't see a pattern (or a reason!!)
    Can somebody please test my code and report if you experienced the same behavior?
    www.vartortech.com
    Solved!
    Go to Solution.
    Attachments:
    Decimal Rounding Classic Rule.vi ‏13 KB

    Enrique,
    This is a fundamental issue with using finite binary representation for numbers.  Event though you display and think of the numbers as decimal representations, the computer stores them in a binary format.  Numbers like 0.0045 or 0.004 cannot be represented exactly in the binary format used by LabVIEW.  Place a numeric control on a new VI. Set the display format to show ~ 20 significant digits.  Type in 0.004 or 0.0045 then hit enter.
    0.0045 -> 0.0044999999999999996600
    The correct rounding for that value is 0.004.  Of course typing 0.004 yields 0.004000000000000000080.
    I do not have Excel so I do not know what it does, but it will have the same issue with approximate representations of numbers.
    There are many posts on the Forums about the number representation issue.
    Also, this is the reason that exact equality comparisons on non-integer datatypes should be avoided or used with great caution.
    Lynn

  • Large numbers calculation problem (determinant calculation)

    Hello experts,
    I have really interesting problem. I am calculatig determinant in ABAP with a large numbers (in CRM 5.0 system).
    My formula for determinant is :
    FORM calculate_determinant USING    det      TYPE zsppo_determinant
                               CHANGING value    TYPE f .
      value =
        (  1 * det-a11 * det-a22 * det-a33 * det-a44 ) + ( -1 * det-a11 * det-a22 * det-a34 * det-a43 ) +
        ( -1 * det-a11 * det-a23 * det-a32 * det-a44 ) + (  1 * det-a11 * det-a23 * det-a34 * det-a42 ) +
        ( -1 * det-a11 * det-a24 * det-a33 * det-a42 ) + (  1 * det-a11 * det-a24 * det-a32 * det-a43 ) +
        ( -1 * det-a12 * det-a21 * det-a33 * det-a44 ) + (  1 * det-a12 * det-a21 * det-a34 * det-a43 ) +
        (  1 * det-a12 * det-a23 * det-a31 * det-a44 ) + ( -1 * det-a12 * det-a23 * det-a34 * det-a41 ) +
        ( -1 * det-a12 * det-a24 * det-a31 * det-a43 ) + (  1 * det-a12 * det-a24 * det-a33 * det-a41 ) +
        (  1 * det-a13 * det-a21 * det-a32 * det-a44 ) + ( -1 * det-a13 * det-a21 * det-a34 * det-a42 ) +
        ( -1 * det-a13 * det-a22 * det-a31 * det-a44 ) + (  1 * det-a13 * det-a22 * det-a34 * det-a41 ) +
        (  1 * det-a13 * det-a24 * det-a31 * det-a42 ) + ( -1 * det-a13 * det-a24 * det-a32 * det-a41 ) +
        ( -1 * det-a14 * det-a21 * det-a32 * det-a43 ) + (  1 * det-a14 * det-a21 * det-a33 * det-a42 ) +
        (  1 * det-a14 * det-a22 * det-a31 * det-a43 ) + ( -1 * det-a14 * det-a22 * det-a33 * det-a41 ) +
        ( -1 * det-a14 * det-a23 * det-a31 * det-a42 ) + (  1 * det-a14 * det-a23 * det-a32 * det-a41 )
    ENDFORM.
    Det values are also f type. Problem is, that for several numbers I got the right values and for another det values I got wrong values... I also try to retype variable value on type p, but without success. Maybe I used wrong types or there is some ABAP rounding of numbers which cause wrong result.
    Any good ideas of solutions. <text removed>. Thanks for your time.
    Edited by: Matt on Sep 14, 2010 9:17 AM

    Hi Lubos,
    phew! that sounds far from SAP scope, but from Maths' numerical methods. Let's see if I can remember something about my lessons at University...
    - One issue can arise when adding and subtracting terms which are very similar, because the error tends to arise quite fast. Try to add the positive terms on one hand, and the negative terms on the other hand, then subtract one from the other.
    - Please take into account that the determinant value can be significantly close to zero when the condition number of the matrix is low, that is, when the range is 4 but the whole determinant is close to 0. Instead, try a [Singular Value Decomposition|http://en.wikipedia.org/wiki/SVD_(mathematics)] or an [LU decomposition|http://en.wikipedia.org/wiki/LU_decomposition]
    I hope this helps. Kind regards,
    Alvaro

  • What formula in numbers can I use when I want to know how much 19 % is of the numbers from (let's say) e6 up to e27 ?  thank you

    what formula in numbers can I use when I want to know how much 19 % is of the numbers from (let's say) e6 up to e27 ?  thank you

    thanks a lot jerry.
    Can I ask you another question?
    it works well but it gives me a number like  14,567
    and I would like it if it will automatic round up an give me the number 15 in this case.
    I do know the seperate folmula to round up numbers but can I combine the two formula's ?
    thank you and bye bye

  • Need help with Rounding a number.

    I have 3 cells each with a formula in them. Please bear with me while I try to explain this.
    Cell D18 contains the formula: =Sum(L18/C5) (L18's value is 58, C5's value is 10), So the value of the cell is 5.8. I need this number to round properly to 6. It does visually on the spreadsheet.
    Cell F18 contains the formula: =Sum(E18/F5) (E18=28, F5=8) So the actual value of F18 is 3.5 which is rounded to 4 visually on the spreadsheet.
    Cell G18 contains the formula =Sum(D18+F18). (D18 visually displays 6, F18 visually displays 4, therefore G18 should display 10). G18 actually displays 9. For some reason the calculations are still based on the actual calculations of D18 & F18, instead of the rounded displayed numbers. How do I get G18 to display the correct number of 10, rather than the rounded down number of 9?
    I'm sure there's a simple fix that I'm just not understanding. I hope I explained my problem well enough, I'd appreciate any help I can get. These numbers are to calculate insulin dosage, so I need to be sure the math is correct.
    Thanks in advance for any help!

    yvieinca wrote:
    I have 3 cells each with a formula in them. Please bear with me while I try to explain this.
    Cell D18 contains the formula: =Sum(L18/C5) (L18's value is 58, C5's value is 10), So the value of the cell is 5.8. I need this number to round properly to 6. It does visually on the spreadsheet.
    Cell F18 contains the formula: =Sum(E18/F5) (E18=28, F5=8) So the actual value of F18 is 3.5 which is rounded to 4 visually on the spreadsheet.
    Cell G18 contains the formula =Sum(D18+F18). (D18 visually displays 6, F18 visually displays 4, therefore G18 should display 10). G18 actually displays 9. For some reason the calculations are still based on the actual calculations of D18 & F18, instead of the rounded displayed numbers. How do I get G18 to display the correct number of 10, rather than the rounded down number of 9?
    The explanation is that you don't understand what you are doing.
    When you ask numbers to display 0 decimal, you don't ask it to round the contents but to display the rounded value.
    A contents remains 3.6 but the display is 4
    an other contents may be 3.6 too displaying 4
    When you sum, you ask number to add the contents (3.6 + 3.6) which is 7.2 and you ask it to display the rounded value of this result. So you correctly see 7 not 8.
    If you want to get what you described, you MUST force Numbers to round.
    First,I don't understand how you may invent such a silly thing like =Sum(L8/C5)
    You are asking Numbers to sum the result of the division L8/C5 to nothing.
    The correct syntax would ask it to calculate the quotient, no less no more.
    =L8/C5
    but here we need to round so, in D18, enter
    =ROUND(L8/C5,0)
    in F18, enter
    =ROUND(E8/F5,0)
    In G18, =Sum(D18+F18) is silly too.
    You are asking nummber to sum (D18+F18) and nothing.
    The correct formula may be:
    =SUM(D18,F18)
    or
    =D18+F18
    Yvan KOENIG (from FRANCE samedi 13 juin 2009 18:05:33)

  • Use of variable types and rounding...

    I'm kinda confused on what variable types to use. I want it so that when I divide two numbers, it'll either round up or down, and give me a rounded number w/o a decimal.
    Examples...
    184/2683=7
    164/2683=6
    I have been fiddling with it for a while now, and I keep getting rounded down numbers, even if the decinal is more than .5. Thanks in advance!

    184 / 2683 = 0.068579947819604919865821841222512 -> 0.07
    164 / 2683 = 0.061125605665300037271710771524413 -> 0.06
    Use Math.rint (please read the javadocs...) and some scaling (multiply by 100.00, divide by 100.0 etc).
    Beware - when printing your result could be:
    0.070000000000001
    or
    0.069999999999998
    instead of the expected value 0.07
    for instance, due to the properties of floating-point arithmetic. If you want to round the number only for displaying it, use java.text.DecimalFormat or java.text.MessageFormat.

  • Combing rounding functions with other functions

    I am using hyperion reports. Is it possible to combine a rounding function with another function? Specifically, I am taking a variance of actual vs budget where actual and budget are % of total functions. The variance I am getting is off (see ex. below.) I need to keep the actual and budget at 1 decimal point. To correct this problem in excel I am able to round the numbers pulled in by essbase. The ex. below illustrates my problem. Actual .2% Budget .2% Variance .1%

    You may want to make a 'Scenario' for rounding that is rounding the input data. If you make it (variance) 2pass, it will show the difference of the rounded numbers (ie. 0%)Rich [email protected]

  • Formating numbers in a form after retrieving from an SQL database

    Hello everyone,
    I am using php to populate a form using numbers taken from an sql database.  I am having a hard time showing decimal places in those numbers.  The code I am using in the value section of the form is:
    value="<?php if (isset($_POST['unit_price_1'])) {
         echo htmlentities( $_POST['unit_price_1'], ENT_COMPAT, 'UTF-8');
         } else {
              echo htmlentities($row_getInvoice['unit_price_1'], ENT_COMPAT, 'UTF-8');
         } ?>" />
    This code rounds all numbers up and eliminates decimal places.  I am trying to show dollars and cents.
    How do I alter the code to accomplish what I want.
    Jeff

    Not sure what might come in your way here, so I just made the following simple test by using a static value rather than one which gets derived from a recordset (the source shouldn´t matter), and this works well for me without seeing the value altered in any way:
    <?php
    $value = "10.22";
    ?>
    <input type="text" name="whatever" value="<?php echo htmlentities($value, ENT_COMPAT, 'UTF-8'); ?>" />
    However,. for displaying numeric values you really don´t need to use  htmlentities/ENT_COMPAT etc etc -- that´s something you´d rather use for displaying textual contents containg special characters like umlauts and such.
    If all you need is to add some degree of protection by escaping special HTML characters (<, >, &, etc.), the function htmlspecialchars() will only be escaping just these characters and leave the rest "as is", whereas htmlentities() is notably more rigi, because this function will convert all applicable characters to HTML entities -- but again: at this point you´re just *displaying* some numeric value, that is, such security measures are pretty much pointless in this scenario, because there´s nothing to protect from ;-)
    Please test what happens when doing away with the htmlentities - thing.
    Cheers,
    Günter

  • Formula Field incorrectly rounded when run on Enterprise Reports, OK in report

    Post Author: beckybear
    CA Forum: General
    We have a report in Crystal Reports 9.  There is a forumla field that has a custom formatting applied to display 2 decimal places.  It works fine when opening the report and running it.  However, when it's uploaded to the enterprise reports server (also version 9) and run from there, it rounds the numbers to have no decimal places.  Any idea what could be going on here?

    Sorry about not including Screenshots, here are a few:
    - Try setting the Formviewer Zoom to page width and resizing the window, at some point the "n" from "dürfen" and the the dot at the end of the sentence should disappear:
    - Shots from the full Report (here "Stundensatz" becomes "Stundens", "von" disappears completely: the second sentence is OK ) - this shows up without manipulating the zoom:
    In the Viewer with the Error:
    When I print this from the Viewer I get:
    When I print directly without the Viewer I get:
    - When I export the Report ( does not matter if rpt or PDF, from the viewer or directly ) the error does not show up.
    - The Problem with the "no printer" option (in my case) was it took a long time with it disabled, not enabled.

Maybe you are looking for

  • Key-nextrec not firing in forms 10g

    I have a code in the above trigger, but it is not firing, I have it in the block property and no other place in the form message('In key next rec----'); message(' '); IF :SYSTEM.Last_Record = 'TRUE' Then Null; Else next_record; End If;

  • How to call a C program in java?

    I would like to call a C program (which does not return anything back to the Java program) from a Java class? Or is there any simple example just to do such a task online? Thanks.

  • Per channel curves?

    In most converters today it is possible to apply color curves. Will it remain as it always was or we can expect this feature in LR3? I understand that could be nicely done in Photoshop, but I'm sure the feature would be useful. Thanks.

  • New puzzles for icomania

    I've solved all the Icomania puzzles and am wondering when there will be an update with new puzzles.  I've contacted Apple support and learned that they contract with a third-party company, games-for-friends, to supply games.  I sent an to games-for-

  • How performance meter in vision assistant calculates estimation time

    Hello... I want to know that how performance meter in vision assistant calculates the estimation time of each step????? I mean what is the concept behind this??? please i need to know... Thanks in advance..