Script / Calculation to round decimals?

Hello all,
I'm building a form to look at the cost of replacing lightbulbs over time, based upon the average life of the lightbulb and average annual operating hours. Normally, I can find this by dividing bulb life over bulb use and multiplying that by the replacement cost, which works fine for our use if you're replacing lightbulbs at least once a year. However, we have lightbulbs that can burn continuously for 5 years, and since you can't by 20% of a lightbulb, I really cant get away with averaging the cost because it's not a true expenditure of money.
So what I'm looking for is a script or calculation that will round "X" (the field in question) to the lowest whole number. When X = 1 that would mean the lightbulb has burned its life hours and would need to be replaced. In that case I can multiply that rounded result by the price and I should be ok.
Basically;
if "X" is greater than 0 or 1, it would round it to 0, even is X is actually .95.
ANY help I can get on this would be very much appreciated! Thanks

You can use the Math.floor method. For example:
var x = 0.95;
var y = Math.floor(x);
app.alert(y);  // Shows 0
If you need more help with creating a custom format/calculate/validate script that does this, post again an include more details about how you want the form to behave.

Similar Messages

  • [JS][CS5] rounding decimals in swatch values

    Hello again,
    I recently made this script to round decimals in the swatch values if there were any. I'm pretty new to JS so this probably isn't the prettiest code so I was wondering if someone had a better way of doing it.  This works, but sometimes it takes a while and I'm pretty sure it is looking at the [paper], [black], and other swatches that can't be changed.  That is why I made it skip the errors during the script...
    function round(color) {
        try { color.space = ColorSpace.cmyk;
        var vals = color.colorValue;
        for (var j = vals.length - 1; j >= 0; j--) {
            vals[j] = Math.round(vals[j]);
        color.colorValue = vals;
    } catch (err) {}
    if (app.documents.length > 0) {
            var target = app.documents[0];
        } else {
            var target = app;
    var myColors = target.colors.everyItem().getElements();
    for (var j = myColors.length - 1; j >= 0; j--) {
        round(myColors[j]);
    alert("Swatches Rounded");
    Any help is appreciated.

    Same bug in ESTK 3 / CS4.
    The data browser definitely has a problem in displaying object properties whose name starts with a (recurring) digit. The issue is not related to property names that could contain a space character —which is not forbidden! Curiously, it seems that the bug only occurs with digits greater than 1.
    Compare:
    var obj = {
         "0a": null,
         "00b": null,
         "1a": null,
         "11b": null
    // The data browser properly displays all obj properties
    and:
    var obj = {
         "2a": null,
         "22b": null,
         "5a": null,
         "55b": null
    // The data browser only displays obj['5a'] and obj['5b']!
    Note that this is not an internal ExtendScript bug. In all cases the object is properly set, the for...in loop works fine and obj.__count__ returns the correct number of enumerable properties.
    Conclusion: ESTK sucks!
    @+
    Marc

  • Errow with IF statement in Scripted Calculation view

    Hi Team,
    I am trying to use IF statement in Scripted Calculation view.
    My scenario is:-
    I need to create a restricted Key figure based on input date from user.
    While i am activating my view system gives "Internal deployment of object failed;Repository: Encountered an error in repository runtime extension;Internal Error:Deploy Calculation View: SQL: transaction rolled back by an internal error: Syntax Error for calculated Attribute: line 29 col 9 (at pos 1501)" error.
    Below is the code i have used in my CV.
    CE_CALC('IF((to_int("BUDAT") >= to_int(2013-01-01),"AMOUNT",'''')', DECIMAL(13,2)) AS "DTR"
    Here, "AMOUNT" is another calculated field created using CE_CALC.
    Without above IF statement my CV runs perfectly fine. The moment i include IF statement it does not activate.
    Kindly provide your inputs.
    Thanks & Regards,
    Anup

    Hi Lars,
    I am extremely sorry about the confusion.
    There was an extra parenthesis in the IF statement which was not allowing the CV to be activated. CV is now successfully activated.
    But my data is not getting restricted correctly.
    It is showing 0 against all the records.
    Below is the sql used for calling the CV.
    SELECT * FROM "_SYS_BIC"."A_123/CV_SCR_BSID_BSAD_ITEMS" ('PLACEHOLDER' = ('$$Currency$$', '''Local'''),'PLACEHOLDER' = ('$$Date_From$$','2014-01-01' ), 'PLACEHOLDER' = ('$$Date_To$$','2014-06-30' ));
    Below is my updated CE_CALC function :-
    CE_CALC('IF(date("BUDAT") >= date(:Date_From) and date("BUDAT") <= date(:Date_To),"AMOUNT",0)', DECIMAL(13,2)) AS "DTR"
    Is there any issue while passing values here?
    Regards,
    Anup

  • Script calculation

    Hey guys,
    I need to write a custom Java script calculation.
    Total1+total2+total3+total4+total5+total6+total7+total8+total9= Ad total....
    ....if  (clicked check box) then 20% off Ad total=?   <-----to be placed in the same field as the Ad total. Thus over writing the orignal Ad total.
    Thanks
    Joe

    Kumar,
    follow next steps:
    1. Create new logic file and name it "TEST" for example
    2. Use next coding in it:
    *XDIM_MEMBERSET P_ACCT = YOUR_P_ACCT_MEMBER
    *IS "YOUR_PROPERTY_VALUE"
    *REC(EXPRESSION=%VALUE%,TIME="2010.MAR")
    *ENDWHEN
    *COMMIT
    3. Validate and save your TEST.LGF
    4. Insert next coding into DEFAULT.LGF
    *INCLUDE ADD.LGF
    5. Validate and save DEFAULT.LGF
    Put your values insted of "YOUR_P_ACCT_MEMBER", "YOUR_PROPERTY_VALUE"
    This coding works for sure.
    U can use ABAP in script logic. The mechanism is described here:
    http://help.sap.com/saphelp_bpc70sp02/helpdata/en/a1/532226947C49A5B2E2BD32450CB2D1/frameset.htm
    Hope that was helpful,
    Dzmitry

  • No rounding decimals

    Hi,
    i am using currency(ZCURR) field.
    which is upto 2 decimals.
    after calculation in currency(ZCURR) field data is comming wotih rounding.
    also i tried with PACKED decimals upto 2
    still it rounding off as i wnat actual value upto 2 decimals
    Ex: ZCURR type VABAK-netwr.
    ZCURR = '2331.437'.
    write : ZCURR
    result : 2331.44  but i want at output "2331.43".
    please help.

    Hi,
    Try below
    SPRO->Sap customizing guide->sap netweaver->general setting->currencies->set decimal places for currencies
    Surendra Jain

  • Calculations with Rounded Numbers

    I've created a form in Adobe X that has a few calculated fields.  For ease of conversation, we'll call them Field A, Field B and Field C (see below).  I need Fields A and B to be rounded to the nearest whole number so that Field C is also a whole number.  I've tried formatting Fields A and B to show no decimals but the calculaton is still being performed on the non-rounded numbers.  Can anyone help with this?  Thanks.
    Field A - Field B = Field C

    George I must be missing something.  I added the math.round functions as shown in your example but now it doesn't calculate at all.  Can you look at the coding shown below and let me know where I went wrong?  Thanks.
    Updated Coding:
    (function(){
    var totalMiles = math.round(+this.getField("Total Miles DrivenRow1").value);
    var homeMiles = math.round(+this.getField("Home Base MilesRow1").value);
    var diff = totalMiles - homeMiles;
    if (diff<0) diff = 0;
    event.value = diff;})();
    Original Coding:
    var totalMiles = +this.getField("Total Miles DrivenRow1").value;
    var homeMiles = +this.getField("Home Base MilesRow1").value;
    var diff = totalMiles - homeMiles;
    if (diff<0) diff = 0;
    event.value = diff;

  • Scripting calculations

    I'm new to scripting, so someone please help me out.
    I have a set of questions in a form, and based on the answer of each question, i need to calculate a certain value.
    Can this be done? If so, under which event do i script and how do i do it?
    Can someone send me an example by putting in 2 questions in a form and calculating the score in percentage?
    Prashant.

    See the sample attached..

  • Need help with Report Script calculation...

    When trying to implement a calculation on 2 members (sales, tax exempt) I am having a problem keeping the report from accumulating the calculation total...
    Any ideas would certainly be appreciated.
    Thanks,
    //*****Script******
    { CALCULATE ROW  "item1" OFF}     //sets variable for first calculation item
    { CALCULATE ROW  "item2" OFF}     //sets variable for second calculation item
    <row("entities", "Measures")
    //{Supoutput}
    {SETROWOP "item1" +}     //starts adding the member
    "Sales"
    {SETROWOP "item1" OFF}     //stops adding the member
    {SETROWOP "item2" +}          //starts adding the member
    "tax exempt"
    {SETROWOP "item2" OFF}     //stops adding the member
    //{OUTPUT}
    { CALCULATE ROW  "total sales" = "item1" - "item2"
    PRINTROW "total sales"}
    //*****what I am expecting******
    north      sales     777.00
    north      tax exempt     27.00
    north      total sales     750.00
    south      sales     796.00
    south      tax exempt     23.00
    south      total sales     773.00     <======     correct
    //******actualreport results******
    north     sales     777.00
    north      tax exempt     27.00
    north      total sales     750.00
    south     sales     796.00
    south      tax exempt     23.00
    south      total sales     1523.00     <==== accumulated number / wrong!
    Edited by: Adam M on Sep 29, 2011 5:06 PM

    You should do this calculation in Essbase, not in report script. Add dynamic calc member "Total Sales" with formula "Sales" - "Tax Exempt"...
    Regards,
    Yuri

  • Script calculation for dimension properties

    Dear Experts,
    I am using BPC 7.0NW,
    My code in Default.lgf:
    *BEGIN
    [P_ACCT].[#B] = [P_ACCT].[A]* [P_ACCT].[C]
    *END
    Now, I want to run this calculation for dimension property wise.
    LIke i want to add dimension properties in above calculations.
    And how do i put "IF" conditions?
    Please help me ...
    Thanks alot in advance.....!

    Kumar,
    follow next steps:
    1. Create new logic file and name it "TEST" for example
    2. Use next coding in it:
    *XDIM_MEMBERSET P_ACCT = YOUR_P_ACCT_MEMBER
    *IS "YOUR_PROPERTY_VALUE"
    *REC(EXPRESSION=%VALUE%,TIME="2010.MAR")
    *ENDWHEN
    *COMMIT
    3. Validate and save your TEST.LGF
    4. Insert next coding into DEFAULT.LGF
    *INCLUDE ADD.LGF
    5. Validate and save DEFAULT.LGF
    Put your values insted of "YOUR_P_ACCT_MEMBER", "YOUR_PROPERTY_VALUE"
    This coding works for sure.
    U can use ABAP in script logic. The mechanism is described here:
    http://help.sap.com/saphelp_bpc70sp02/helpdata/en/a1/532226947C49A5B2E2BD32450CB2D1/frameset.htm
    Hope that was helpful,
    Dzmitry

  • Apple Calculator inappropriately rounds fractions in RPN mode

    It seems this is a bug in the Apple-supplied calculator, and I'm hoping someone else can replicate it.
    Steps to replicate:
    Open the Apple-supplied Calculator.
    Select RPN under the View menu.
    Set the Precision under the View menu to 11 or 12.
    Enter any calculation with fractions (e.g. 2.57 + 3) using RPN, with the following keystrokes:
    2.57
    Enter
    3
    +
    The result will be rounded up or down depending on the resulting fraction, ignoring the Precision settings. In this example the answer is displayed as 6. If you don't use RPN, the result is correctly displayed as 5.57.
    Work-around: Don't use RPN or use another calculator application.
    I've already reported this to Apple's feedback area.
    PowerMac G5 Quad 2.5 GHz   Mac OS X (10.4.3)   NVIDIA GeForce 7800GT

    Interesting.
    Yet
    3
    Enter
    2.57
    +
    Gives the correct result.
    Try
    2.57
    Enter
    3.00
    +

  • Repeatable subforms script calculation syntax

    My form contains a subform (row) with 5 radio buttons, with values (scores) of 5,4,3,2, and 1. The user may add another of these subforms by clicking a button.
    My intention is to set a field with the average score -- that is, obviously, the total scores, divided by the number of rows. Here is my FormCalc for the calculate event of the Average field -- complete with error message:
    b Script failed (language is formcalc; context is
    b xfa[0].form[0].form1[0].Pg1[0].#subform[2].EssentialAv[0])
    b script=
    b var totPts =
    b Sum(form1.Pg1.EssentialJobRow[*].RadioButtonList.#field[3])+
    b Sum(form1.Pg1.EssentialJobRow[*].RadioButtonList.#field[2])+
    b Sum(form1.Pg1.EssentialJobRow[*].RadioButtonList.#field[1])+
    b Sum(form1.Pg1.EssentialJobRow[*].RadioButtonList.#field[0])+
    b Sum(form1.Pg1.EssentialJobRow[*].RadioButtonList.#field[4])
    b var numRows =
    b Count(form1.Pg1.EssentialJobRow[*].RadioButtonList.#field[4])
    b //$.rawValue=totPts
    b //$.rawValue=numRows
    b $.rawValue = totPts/numRows
    b Error: arithmetic over/underflow.
    I have used the commented lines in debugging, to prove that the total score and the number of rows are being calculated correctly. There is always at least one instance of the subform, so numRows is always greater or equal to 1 -- never 0.
    This is such a simple thing, I know the answer must be staring me in the face, but I do not see it.
    Thanks for any suggestions you may have.

    I was mistaken. The number of rows *does* go to 0.
    To test, I displayed the total points and number of rows variables with two message boxes.
    When I click the button to add a row, the point count and the row count increment properly.
    However, when I click one of the unselected radio buttons in a row, the point total increments correctly, but the row count sometimes is 0.
    I suspect it relates to the sequence of events related to my use of the Count function to try to determine how many instances of the row exist.
    Back to the drawing board to find a more appropriate way to determine the number of subforms I have created . . .

  • Inline Calc Script Calculation

    Hello! I'm being lazy and i'd like to calculate a variable in a calc script using an inline calculation, choosing a very simple example:
    *1. VAR WEIGHT = 1;*
    works successfully, but
    *2. VAR WEIGHT=1 + 2;*
    fails with Error: 1012001 Invalid Calc Script Syntax [
    variations i've tried on *2* also fail WEIGHT = (1+2);, WEIGHT ( WEIGHT = 1+2; ); etc...
    Any ideas?
    Graeme.

    Setting a variable to a constant is fine byitself Var Weight = 1; but if you want to do math to set the varialbe it needs to be in a block statement. When you exit the block, the variable is no longer available. Try
    Var Weight;
    Weight = 1 + 2;
    "Weighted Sales = weight * sales;
    Notice the parens starting and ending the command that is the block command. Depending on what you are doing you might need to specify a member starting th command
    "Weighted Sales"(
    )

  • Rounding decimals

    Dear all,
    Is there any way to restrict the Signed data decimal to 2 places? We have decimal formatted in the BPC Excel front end. But this doesnt stop data from Input schedule restricted to 2 decimal places in fact table.
    Some users wrongly enter data with more than two decimal places in input schedule. Although such data is rounded off in the excel front end view, it doesnt get rounded in the fact table. We have issue when we try to extract such data using custom SSIS. We have option to round off at the time of extraction using custom SSIS. But when we extract huge data records, there are some reconciliation differences due to rounding. So the BPC data and extracted data differs. Is it possible to round the data at face table level?

    Hi Lokesh,
    We also have the same requirement.  No decimal places required.  I had done the changes to include SIGNED_DATA_FORMAT to 13.0, and have rebuilt the indexes on the Consolidaiton Cube. However it still doesn't work as expected.
    When I run currency conversion, the coverted values still shows decimal places.
    Are we missing any step here?
    We are on BPC 10NW SP05.
    Please suggest.
    Regards,
    Rashmi

  • Rounding decimals using FM REUSE_ALV_HIERSEQ_LIST_DISPLAY

    Hi all.
    I am having no luck get values to round in FM REUSE_ALV_HIERSEQ_LIST_DISPLAY.  I have managed to get them to round in REUSE_ALV_GRID_DISPLAY by setting DECIMALS_OUT to a value of 0.
    Any help would be very much appreciated.
    Anthony

    Hi Anthony,
    <b>1</b>.
    If DECIMALS_OUT is working properly for REUSE_ALV_GRID_DISPLAY,it should work for REUSE_ALV_HIERSEQ_LIST_DISPLAY.Becoz there is no difference between two fieldcatalogs .
    <b>Thanks,
    Venkat.O</b>

  • Logic Script - calculating Accounts with BAS()

    Hello experts,
    I am trying to write a script that includes a BAS formula to gather the sum of all the descendants.  I want to pull the value of all, less a few accounts.  This is the line of code I have, and it gives me an error around the BAS formula.  Is there a better way to do this?
    *WHEN ACCOUNT
    *IS BAS(P_EA3700)
    *REC(EXPRESSION = ([ACCOUNT].[BAS(P_EA3700)] - ([ACCOUNT].[A_51800020])), ACCOUNT = "A_FCST_3700", AUDITTRAIL = "CC")
    When I put an actual Account in place of the BAS forumla, it works.  The EA3700 has a lot of accounts within it, and i need the value of all, less this 51800020 account, and a couple others I will add when I figure out this code.
    Thanks!

    It Appears I did not copy all the way down the log, that is what caused the confusion.  Below are the records.  After reviewing this, I did some digging.  It appears the pull with the 40 records is pulling ALL the accounts with data for this entity, except those two we outlined in the script.  Including accounts that are not within the P_EA3700.  For Example, the first record, the account 46001000, is a personel expense account.  That appears to be the difference, when using the ELSE code, it appears to not keep the scope within the BAS(P_EA3700)
    DATA TO WRITE BACK:
    ACCOUNT AUDITTRAIL CATEGORY COST_CENTER RCOST_CENTER RPTCURRENCY TIME SIGNEDDATA
    A_51800020 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 70.22
    A_51800028 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 3738.52
    A_55200000 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 100.00
    A_55205000 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 5288.00
    A_55508000 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 1364.07
    A_56230000 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 - 9718.73
    A_98420599 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 315.24
    A_98420601 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 6587.39
    A_98420625 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 282.44
    9  RECORDS HAVE BEEN WRITTEN BACK.
    40 Record Log
    DATA TO WRITE BACK:
    ACCOUNT AUDITTRAIL CATEGORY COST_CENTER RCOST_CENTER RPTCURRENCY TIME SIGNEDDATA
    A_46001000 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 35119.82
    A_46006000 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 3503.76
    A_47100000 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 2134.17
    A_47100001 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 499.12
    A_47100200 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 185.63
    A_47100300 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 784.83
    A_47100900 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 278.45
    A_47105000 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 - 4982.17
    A_47200000 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 3846.25
    A_47203000 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 886.96
    A_47203001 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 2072.07
    A_47206000 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 867.61
    A_47208500 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 2168.67
    A_47209500 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 5000.00
    A_47304000 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 3.39
    A_51300000 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 2089.09
    A_51500000 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 17761.33
    A_51800020 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 70.22
    A_51800028 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 3738.52
    A_52105001 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 41.47
    A_52207000 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 8.26
    A_52208500 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 2199.86
    A_53310000 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 549.95
    A_53320000 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 205.20
    A_55200000 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 100.00
    A_55205000 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 5288.00
    A_55508000 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 1364.07
    A_56230000 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 - 9718.73
    A_92001102 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 5.00
    A_92001199 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 - 5.00
    A_97420599 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 315.24
    A_97420601 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 6587.39
    A_97420625 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 282.44
    A_97431010 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 - 74024.00
    A_97431030 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 - 13122.00
    A_98420599 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 315.24
    A_98420601 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 6587.39
    A_98420625 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 282.44
    A_98431010 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 - 74024.00
    A_98431030 ECC Actual CCA_7340016 RCCA_NONE LC 2013.01 - 13122.00
    40  RECORDS HAVE BEEN WRITTEN BACK.

Maybe you are looking for