Rounding to nickel formula...

Hi,
I have a formula for rounding a value to the nearest nickel. It seem that it does'nt work propably. The value of tempCalc after calculation is 3245.421123 and the result should be 3245.40 but I receive 3245.45 instead.
// round to the closest nickel (0.12 ==> 0.10 and 0.13 ==> 0.15)
private double RoundToNickel(double amontValue)
double tempCalc;
int modCalc;
tempCalc = ((double)(Math.round(amontValue*100)));
modCalc = (int) tempCalc % 5;
switch (modCalc)
case 1:
tempCalc = (tempCalc / 100) - .01 ;
break;
case 2:
tempCalc = (tempCalc / 100) - .02;
break;
case 3:
tempCalc = (tempCalc / 100) + .02;
break;
case 4:
tempCalc = (tempCalc / 100) + .01;
break;
default:
tempCalc = tempCalc / 100;
break;
tempCalc = ((double)(Math.round(tempCalc*100)))/100;
return tempCalc;
So I try the next one and the problem is that I receive 3245.40 but if I try with an other value I receive 3245.425 for example.
private double RoundToNickel(double amontValue)
double tempCalc;
// Test for rounding issues
double tempdouble;
// Determine the single cents
tempdouble = (amontValue * 10) % 1;
tempdouble = ((double)(Math.round(tempdouble * 1000)))/1000;
if (tempdouble > .5) {
tempCalc = amontValue + (((.5-tempdouble)* -1)/10);
} else {
tempCalc = amontValue - (tempdouble / 10) ;
return tempCalc;
Is there someone who can help me with this.

This should be what you want. Note that I coded it using binary floating point throughout, which is the cause of the "unusual" format of the results. This can be cured by formatting the results with DecimalFormat class.
There is a very small (by finite) possibility that an input will disrupt the code, again due to the imprecision of binary floating point numbers in representing decimal numbers. This probablilty can probably be ignored for practical purposes.
for(x = 0; x < 21; x++)
//-------Code starts here. Provide a value for inout.
double input = .01*x;
double nickels = input * 20;
double roundedNickels = (nickels - (int)nickels < .5) ? Math.floor(nickels) : Math.ceil(nickels);
double roundedOutput = roundedNickels * .05;
//-------roundedOutput contains the rounding of the input to the nearest .05
System.out.println("Input = " + input + "  Result = " + roundedOutput);
}For illustration purposes I placed the code in a loop and printed the following results:
Input = 0.0 Result = 0.0
Input = 0.01 Result = 0.0
Input = 0.02 Result = 0.0
Input = 0.03 Result = 0.05
Input = 0.04 Result = 0.05
Input = 0.05 Result = 0.05
Input = 0.06 Result = 0.05
Input = 0.07 Result = 0.05
Input = 0.08 Result = 0.1
Input = 0.09 Result = 0.1
Input = 0.1 Result = 0.1
Input = 0.11 Result = 0.1
Input = 0.12 Result = 0.1
Input = 0.13 Result = 0.15000000000000002
Input = 0.14 Result = 0.15000000000000002
Input = 0.15 Result = 0.15000000000000002
Input = 0.16 Result = 0.15000000000000002
Input = 0.17 Result = 0.15000000000000002
Input = 0.18 Result = 0.2
Input = 0.19 Result = 0.2
Input = 0.2 Result = 0.2

Similar Messages

  • Rounding in a Formula

    I need to round the result of this formula to 3 decimal places for the following:
    If not isnull ({TRACKING_FILE.f7070#price_lock_exp_date}) and
    ({TRACKING_FILE.Orig_Points} + {TRACKING_FILE.Disc_Points}) > 0 then
    CSTR({TRACKING_FILE.Orig_Points} + {TRACKING_FILE.Disc_Points})
    I've tried using the Round (,), but no matter where I put the word Round and the parentheses and comma, I get errors.  This looks like it should be simple, but since I've never used rounding in the formulas, I'm missing something.  I can't round it through the format field function because there are other formulas being used to print words in the same column under certain circumstances.
    Help will be greatly appreciated.

    The result of the formula should be numeric.
    Place the formula on the report.
    RIght-click and choose Format Field.
    In the Format Editor (number tab) - click on the Customize button.
    In the Custom Style window, Number tab, set the rounding as you'd like.

  • Rounding down a value

    hi all, is there any way in PLD to round down a value ?
    there is only round function in formula.
    thanks for every comments

    Hi Ivin,
    Yes, Round Function only in formula on PLD.
    any other related Function not in Formula on PLD.
    for example,
    DocTotal Field ID -> F_123 - 25412.76
    Round(F_123,0)
    Result(in print): 25413
    Regards,
    Madhan.

  • How to use rounded values in BEx Formulas

    Hello,
    I have the following question. Is it possible to use rounded values up to a certain # of decimal points in BEx Formulas?
    I have the following problem.
    Consider this:
    keyfigure val 1 = 0.416666667
    keyfigure val 2 = 72
    val 3 (BEx Formula)  = val 2 / val 1 = 172.799999862
    However, what I need to do is this.
    val 1 & val 3 should rounded up to 2 decimal points. So, I really need the report to show this:
    val1 = 0.42
    val2 - 72
    val 3 = val 2 /val 1 = 171.43
    I changed the number of decimal places on val 1 and val3 to be 0.00. However, it appears that these rounded values are not taken into account in  the Formulas, as if the OLAP still uses the original values from the backend with 9 decimal points. So, no matter how many decimal points I use on the Display tab for a key figure, my val3 or result of my formula is always taking into account the 9 digit decimal values, not rounded values that I want. So in the example above, my val 3 comes to 172.80, which it should be 171.43 instead of you use the rounded values in the calculation.
    Please let me know if there is any workaround where I could force my BEx Formula to utilize the rounded values and not actual values from the backend DSO. Or any other solution.
    Thank you

    If you create a Formula in BEx Query Designer like the one below, it works:
    val3 = val2 / ( TRUNC ( ( val1 * 100 + 0.5 ) ) / 100 )
    The TRUNC function (among other things) actually ensures that your formula takes into account the rounded values that you want.

  • How to use Round off function in TAX Formula

    Dear All,
             I have to do Round off in the Tax Formula. Hence I was suggested by the SAP Forum Team to use Round off function in the Tax Formulae.
             But sir I don't know how to use Round off function in the Tax Formulae.
            For Eg. BaseAmt = Total
                        TaxAmt = BaseAmt * Rate
               Now within this Eg. How will i use the Round off function and where i will use it.
               Please guide me with example.
      Regards
    Hitesh Parsawala

    Hi Hitesh,
    you can do like this
    Cess_ST_TaxAmt=Round(Cess_ST_BaseAmt*Cess_ST_Rate,0)
    where you can introduce rounding function by choosing from dropdown available in Operation and by click on Insert.
    It will post following in formulla window
    Round (Number, Decimals as Number)
    where in parameter you have to give 1.Number-which is to be round and 2.Decimals as Number-as per your requirement like by 2 decimal or 0 decimal
    If required give me call,
    BR
    Samir Gandhi

  • Round badi does not work in default formulas triggered when sending a value

    I have implemented the round BADI from sdn (how to). Problem is that it works perfect when :
    -  I execute it in UKT
    - I run it as a data manager package
    - I put it in default formulas and run the default formulas as a packe
    It however doesn't work when it is executed in default formulas when sending a value from an input scheduls.It gives an error "error converting records -  the root element is missing"
    Anybody a clue ?
    Cheers
    Nico

    Answering to myself!
    Code correction required:
    loop at it_cv into ls_cv.
    *{   INSERT         BPCK900005                                        2
    CHECK ls_cv-dimension NE 'MEASURES'.
    *}   INSERT

  • Formula rounding to nearest whole number

    Hello,
    I have created the following formula ( Metrics."# of Leads Resulting in Won Opportunity"*100 /Metrics."# of Leads" ) and displayed the results in percentage but it looks to round to the nearest whole number does anyone know why this might happen. Also i am using 2dp in the results i am hoping to get the actual result rounded to 2dp and not the nearest whole number.

    Hi !
    I think that if you add the ROUND function, this will work... :
    ROUND(Metrics."# of Leads Resulting in Won Opportunity"*100 /Metrics."# of Leads", 2)
    Hope this will help, feel free to ask more !
    Max

  • Increasing percentage formula, rounding up in Numbers '09

    Having a hard time with numbers formulas... I need to increase a sum by 9%, rounding up. I have this formula: =roundup(81.09,0) but I know I am missing something.
    Anyone? Bueller? Thanks so much!!
    **blip**

    ROUNDUP(81.09,0) will round 81.09 to the nearest higher whole number = 82.
    To increase a number by 9%, you multiply by (1+9%) or 1.09.
    81*1.09=88.29
    If you want to round it up to a whole number then it would be ROUNDUP(81*1.09,0) = 89

  • Formulas and Rounding

    Two things here that I've found problematic.
    -How can I set cells to display the formulas I have typed into them, rather than the formula outcome?
    -My Numbers is rounding 5s down, not up? Is this An American thing or a fault in Numbers?
    Anyone got any ideas?

    Mine (US English) seems to be always rounding up... 1.5->2, 2.5->3
    Are we testing this the same way? I've entered some numbers (1.5, 2.5) and then referred to them in another cell with a format of zero decimal places.
    In my experience there are three rounding schemes use to handle 5s:
    (1) Round 5s down
    (2) Round 5s up
    (3) Round 5s even... 1.5->2, 2.5->2, 3.5->4, 4.5->4, etc, used so that on average half are randomly rounded up, half down.
    Of these 3, I would say that (1) is least common. Are you sure that rounding is occurring? Does 1.6->2?

  • Problem in formula:value getting round off

    Hi All,
    I  need to divide 2 keyfigures and fill it in one keyfigure..
    What i am doing , In transformation  i have 2 fields in datasource one is value and other is quantity and i  am mapping these 2 fields with one keyfigure in ODS..
    I am creating formula in rule in which I am dividing value by quantity (value/quantity) but when i am running DTP and loading data the value in my keyfigure is coming after rounding off... like
    I have value 4,311,781.58 and quantity 16,200.000 , if i divide i should get  266.159
    but in my ODS this value is coming as 266.16..
    Please advise how to remove this roundoff functionality...
    Regards
    Shweta

    Hi shweta,
    You have two options in this case.
    1. Go to your created key figure. After clicking on change go the tab 'Additional properties".
        There you can see Decimal Places under business explorer. you can change the number of places if you know to what    places you need the calculated value.
    2. Go to your created key figure. After clicking on change go to the first tab Type/unit and change your data type to FLTP- Floating point number.
    Hope it helps.
    Thanks,
    Rahul

  • I don't want integer division to round off. Especially in formula node. How?

    Why does integer division in a formula node round to the nearest integer. I was having a problem with my application and freaked when I found that this was the problem. I'm a C programmer learning Labview and I just can't believe I can't stop it from rounding. This is very frustrating. It's telling me 3/4 = 1. Well not in my world. Is there any way I can get it (especially in the formula node) to not round off division with integers? And also division in general?
    Thanks

    Pls see attached... is that ur problem?
    Ian F
    Since LabVIEW 5.1... 7.1.1... 2009, 2010
    依恩与LabVIEW
    LVVILIB.blogspot.com
    Attachments:
    round_off.vi ‏18 KB

  • Formula rounding (?)

    Post Author: hollyschulz
    CA Forum: Formula
    I'm not even sure if this is the problem, but I can only assume it is....
    Here's my formulas:Main (the one whose result I can't get right):   truncate({@key_pct_avg}\{@distinctcount}, 4) - note, i just added the truncate to try working out the rounding, it didn't help.@key_pct_avg = (Sum ({Sheet1_.KEYED ERRORS}, {Sheet1_.name}) / (Sum ({Sheet1_.KEYED Records}, {Sheet1_.name})))*100@distinctcount = distinctcount({@month})@month= if month({Sheet1_.DATE})=8 then "August" elseif month({Sheet1_.DATE})=9 then "September" elseif month({Sheet1_.DATE})=10 then "October" elseif month({Sheet1_.DATE})=11 then "November" elseif month({Sheet1_.DATE})=12 then "December"
    Since my record selection only includes August - lastfullmonth, the @distinctcount come to "2".The value for ONE @key_pct_avg is 2.89.When you work out the formula it would be 2.89\2 = 1.445 The results I get from Crystal is 1.00. Now, there are other values for the formula throughout the report... But Crystal always gives a rounded number with no decimal values! Help!

    Post Author: SKodidine
    CA Forum: Formula
    Easy enough.
    In CR, the \ is different from / when it comes to calculations.
    \ = integer divide. Divide the numbers and truncate the quotient to an integer.
    / = do the division and display the entire quotient including decimals.
    In your formula truncate({@key_pct_avg}\{@distinctcount}, 4)  you are asking it to give the quotient as an integer value with no decimals.
    2.89\2 = 1.445 and truncating the quotient to an integer the result is 1.  Change the division operator to / and it should solve your problem.
    2.89/2 = 1.445
    change the formula to: {@key_pct_avg}/{@distinctcount}

  • Bex Formula Rounding Up Values!

    Hi Guys,
    I am doing a calculation in BEx where I divide items by days (items%Adays) but the result value is 4.77 on a calculator but Bex rounds up to 4.0!  All my results differ by the fraction so I need to the 4.77 to come up else all columns will be 4.0!
    In properties I increased the decimal places to 2 d.p for the results formula field but it didnt work!
    Anyone have any ideas?
    Thanks
    DV

    Depesh,
    This is the same as posted by AVR but contains the procedure also...
    Check the following ,
    have you defined the decimal places in the KF properties . Right click on KF and select properties , the decimal places will be a dropdown.
    Set the same to the first value in the dropdown and then execute your query , come back with the results.
    Arun
    Assign points is helpful...
    Message was edited by: Arun Varadarajan

  • Work center formula - rounding to zero?

    Hi
    I have set up a new formula for a work center, using a new parameter Z_BKP5 (Parameter1.jpg). It should be fixed to 2000.
    My formula is: Operation qty/Z_BKP5* Variable machine time.
    However, if my operation qty is bigger than Z_BKP5 (2000), then I get the result (Test1.jpg), for example 2000/2000*180 MIN => result is 180 MIN
    If my operation quantity is smaller, I don't get anything calculated (Test2.jpg). The same happens on Test formula screens as well on planned orders.
    Example 1900/2000*180 MIN
    Is it some rounding issue? I have tried finding a parameter in customizing for this, but I cannot find anything related. Can this be solved somehow, or is this standard behaviour?
    Thank you

    Just for future help, I'd expect that means your data container is integer.  In that case, it's important to do your multiplications first and your divisions last.
    An alternate problem that you can also run into is that you can exceed the max size of the container and get an overflow.  Then you need to look at the expected size of the max and min values of each variable and try to work them in  alternately so as neither to go below 1 nor above max value.
    Neal

  • Formula for rounding down a number in a Pages WP table cell

    Could someone advise me on a formula? I know the answer might be straight-forward, but am not used to needing anything other than very elementary formulae, and cannot find a list in the Pages Help guide.
    I have a Pages WP document which contains a simple table. One cell is the sum of 4 others divided by 4, and is set to show 2 decimal points, e.g. 7.35, 6.75 etc. (This number is never above 9.00).
    I need this sum to always round down to the nearest .5 or .0, i.e. 7.35 would round down to 7.00, and 6.75 would round down to 6.50. (Simply limiting the decimal point to 1 doesn’t do it, because 6.75 would round up to 6.8).
    Any help much appreciated,
    Graham Falvey

    I would try with
    =ROUND(B*2,0)/2
    but I'm not sure that you really want that 5.25 returns 5.5
    Explanations about this kind of problem which are the same in Keynote, Numbers and Pages are available in the Numbers Guide.
    Yvan KOENIG (VALLAURIS, France) mercredi 2 septembre 2009 20:55:36

Maybe you are looking for

  • Itunes Home Sharing with Ios7 Ipad

    Upgraded Ipad to Ios7 (what was I thinking) and now have upgraded Itunes on my laptop to 11.1 Music and Video apps on my Ipad show my Itunes Library Name correctly, but wont load them, after 30secs or so,comes up with "Unable to turn on home sharing"

  • Foeign Trade Tab in purchase order (ME21N)

    Hello, How can I make sure that i always have a Foreign Trade Tab in my purchase order. This means; Even if the order is from a BE vendor to a BE plant? Thanks, Oktay

  • How to activate  ABAP Dynrpo in SE80

    Hi Experts, I am using ECC 5.0, and I want to create a web dynpro using ABAP, but in SE80 transaction this option is deactivated, how to activate it ?

  • How to create surrogate key in dimension without unique value

    Hi, I have a dimension where there is no column with unique value. I want to add a surrogate key to replace the existing primary key which is derived from concatenating 3 columns(e.g. 'A'||'B'||'C'). I'm thinking of using sequence. But this won't all

  • Where Does iPhoto Get The Date?

    I'm not sure I understand where iPhoto is getting the information for a photo's Date. Is it coming from the photo's metadata? If so, which field? I have scanned old photo and I want iPhoto to show the Data that they were originally taken, not when th