Rounding a percent to a whole number

Hello,
I'm still fairly new to performing script calculations and with this particular one seems a bit more complex for me.
I'm trying to determine the percent difference between 2 numbers and display the percentage as a whole number. Logically my calculation looks like
(numericField1 - numericField2 / numericField1 * 100)
(ex. 1000 - 850 / 1000 * 100 = 15%)  
I need assitance with my calculation and especially rounding the % to a whole number. I would not like any answers displayed like 22.66666%
The code below is somethig I tried
event.value = roundNumber( ( this.getField(numericField1).value - this.getField(numericField2t).value  )  / this.getField(numericField1).value , 2 ) + '%';
function roundNumber(num, dec) {
        var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
        return result;
Any advice would be great!

Actually Adobe makes this really simple for you.  If you use a numeric field to display the result, the display pattern for the field will control how the number is shown.  You can set a percentage pattern:"num{zzzz9.99%}" to control how many digits will be displayed, and how many digits will be significant past the decimal point.  If there are more digits, Adobe will automatically round the number.  In the attached example I used the pattern
"num{zzzz9%}" to ensure that only a whole number will be displayed.  Adobe will use normal rounding rules: 0-4 rounds down, 5-9 rounds up.
Additionally, the percentage pattern will automatically multiply the field value by 100, so you don't need to do that in your script.
For the example attached, I added your calculation as FormCalc script to the Calculate event of the result field.  The script is now simply:
(NumericField1 - NumericField2) / NumericField1
Adobe takes care of the rest.

Similar Messages

  • Rounding text size to nearest whole number?

    I've had to rescale some artwork, but now I'm left with type sizes that are 71.68px tall, 34.51px tall, etc.
    Is there a script that'll snap all the text in a document to it's nearest whole number or 0.1 decimal?

    // rounds the size of text in all textFrames in your document
    var aTFrame = app.activeDocument.textFrames;
    for ( i = 0; i < aTFrame.length; i++ )
    var fractionSize = aTFrame[i].textRange.characterAttributes.size;
    var RoundedSize = Math.round(fractionSize);
    aTFrame[i].textRange.characterAttributes.size = RoundedSize;
    redraw();
    This will do all the text frames. Copy the above, paste it into a text editor or the Adobe ESTK (ExtendScript Tool Kit) and save as a plain text file with a .jsx extension. Place it into Applications/Adobe Illustrator CSX/Presets/en_US/Scripts folder and restart AI. Run it by having a document open in AI and call it from File>Scripts>scriptname.

  • I have a calculation in a5 and need the answer rounding up to the next whole number

    I have a calculation in cell a5 and need the answer rounding up to the next whole number

    Hi,
    I am using numbers
    A1 x A2 = A3       A4 is A3 divided by 2.88.  Indeed to round up the answer in A4 to the next whole number
    Eg 4.5 x 3.7 = 16.6 sq meters as an area , divided by 2.88 ( area of 1 board) = 5.78 boards so I need to buy 6 and quote for 6
    Cheers

  • How to return whole number using round function

    hi
    can i get sql query using round function how to return whole number value

    Hi welcome to the forum. if you want whole number value what does it mean
    1. whether you want the whole number greator than or eqaul to that number example for 12.6 you want 12 or 13
    see below example
    1.  SQL> select round(12.5) from dual;
    ROUND(12.5)
             13
    2.  SQL> select round(12.4) from dual;
    ROUND(12.4)
             12
    3.  SQL> select floor(12.5) from dual;
    FLOOR(12.5)
             12
    4. SQL> select floor(12.4) from dual;
    FLOOR(12.4)
             12
    floor will always give you a round value which is a integer or whole number less than or equal to but output of rond will differ if the value is greator than 12.5 it will give 13 but if it is less than 12.5 it will give 12, so depending on your requirement you can choose which function to use. similarly if you always want to get the whole number greator than the number you can use ceil as below
    SQL>  select ceil(12.3) from dual;
    CEIL(12.3)
            13
    SQL>  select ceil(12.8) from dual;
    CEIL(12.8)
            13

  • Rounding up to nearest whole number question

    I have a calculation script that sometimes returns a decimal result. How would I create a script that would round that decimal up to the next whole number? Anyone have any idea's?

    okay, I am not very good with this. That command is new to me. Where would I place that script if I already have a javascript script in the calculate event of that numeric field I am trying to get rounded up?
    I basically have the javascript code in the numeric fields calculate event set to
    this.rawValue = subform1.numericField1.rawValue;
    I tried putting your script on the change event hoping I could use formCalc there but get a error when testing saying Ceil is not defined. Thanks

  • Rounding to a whole number

    What is the proper syntax for rounding to a whole number.  In my spread sheet I have a function set up to apply a divisor to cost, in this case  = F7 $625 / G7 .65 = $961.54.  I simply want the number to round to the nearest whole dollar amount  $962.00

    Hi ghemmen,
    or you could just do with formatting.
    quinn

  • Rounding off to nearest whole number without condition

    hi,
    i want to round a real number to an integer value,,wihout any conditions like
    10.01 should be 11
    10.1 should be 11 and like that
    is it posible to do it?
    thanks in advance.
    amit

    It doesn't look like you are trying to round to the nearest whole number here. It looks like you are trying to find the smallest integer value that is greater than or equal to the real number. If so, you would want to use the CEIL function (i.e.
      1  SELECT CEIL(10.01)
      2*   FROM dual
    SCOTT @ hp92 Local> /
    CEIL(10.01)
             11Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • 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

  • 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

  • % formating if a whole number is inputted

    Hello:
    I have a numeric field on my form. I clicked on the field, went to the "Cell" tab clicked on "Patterns" and in the "Display" tab set my pattern to " num.percent{} "
    My problem is that my user wants it to display 10% when they key in "10" (whole number) currently keying in "10" displays 1,000%.
    So far the only way to display 10% is by keying in ".10". I understand why .10 gives me 10% but the behavior of the users will be to key in a whole number.
    What is the best way to solve?
    Thanks,
    Keith.

    That worked perfectly in fact I ended adding to it num{99.99'%'} to display less than 1 percent values.
    I do have another quick question. In another field where I have dates. I have the following setting in the display pattern:
    date{MM/DD/YYYY}
    My issues is that it will only format/display if I click the calendar pop up and select a particular day. That is to say if I was to input the date manually like 06262008 or 6262008 it would display the number like I just inputted not in the display pattern that I had set (06/26/2008)
    Any more ideas how to solve?
    And thanks very much :-)
    Keith.

  • How to add 2 decimal places if the number is whole number(Integer)

    Hi Gurus- I had a requirement to add the zeros for two decimal places even the number is an whole number.
    Example: I had a column which i gave the datatype as Number(8,2) .While Inserting from the flat file to the custom table column,i am rounding it to 2 decimal places.But if its the whole number i want that also to be rounded to 2 decimal places.
    1) 3456.89675 It's getting inserted as 3456.89
    2) 123 It's getting inserted as 123 (Instead i want this to be inserted as 123.00)
    3) 123.50000 It's getting inserted as 123.5 (Instead i want this to be inserted as 123.50)
    Can you please let me know how can i achieve it to insert any number(decimal or whole number) from the flat file as 2 decimal places in the custom table column.
    Thanks in advance.

    Please do not post duplicates -- To update the date for the first of the month

  • How to get only the whole number omitting the decimals

    Hi Experts,
    I want to get only the whole number of a output field. For example  i am getting an output as 8.766 , i need only the value 8 .
    I checked by moving the values to integer field but i am getting the rounding value 9 .
    I want only the whole value 8.
    Please help me out..
    thanks & Regards.
    Reena..

    Hi Reena,
    Unfortunately when you assign a packed number to a character, numeric or even a packed no without a decimal value SAP does a internal conversion of rounding these value. So direct assignment would won't work for your case.
    You can use the following logic instead for getting the whole number.
    DATA : LV_VAR1 TYPE STRING,
                LV_VAR2 type p DECIMALS 3 value '8.766'.
    LV_VAR1 = lV_VAR2.   " LV_VAR1 would contain 8.766 without rounding.
    write  : LV_VAR1(1).   " LV_VAR1(1) contains 8 which you can assign to any target variable.
    I think there is no addition so as to avoid this internal rounding.
    Try and let me know if it works for you..
    Cheers
    Ajay

  • Queue SYSFAIL after message split "Whole number overflow on addition"

    Hi,
    I'm using a message mapping in PI 7.1 to split a message in several messages for each line of an invoice. It's a mapping 1 to 0..n. Everything went well since I had maximum 100 invoice lines to split (then 100 messages at the output of the mapping).
    But since I have now messages with 200 invoice lines, everytime the queue is stopped in SYSFAIL status with a message "Whole number overflow on addition". But all messages are processed even if the queue is stopped.
    ST22 gives me a COMPUTE_INT_PLUS_OVERFLOW in the method determin_message_size. It seams that PI doen't support a large message at output of a mapping. How can I split the message into multple messages at the outplut of a message mapping ?
    Does anyone have a solution ?

    Hi,
    I guess you can use the Message Packing feature.
    See below the links to help you:
    http://help.sap.com/saphelp_nwpi711/helpdata/en/46/7ef9124f176be3e10000000a155369/frameset.htm
    http://help.sap.com/saphelp_nwpi711/helpdata/en/46/7a6e3469454b2be10000000a155369/frameset.htm
    http://help.sap.com/saphelp_nwpi711/helpdata/en/46/79e8e13872275ae10000000a11466f/frameset.htm
    Regards,
    Caio Cagnani

  • Whole number field formatted as timezone in CRM 2013 SP1UR1 gives error on saving

    Hi,
    I added a whole number field formatted  as time zone to the appointment form and when I save the record I get an error saying
    Crm Exception: Message: An unexpected error occurred., ErrorCode: -2147220970, InnerException: System.InvalidCastException: Unable to cast object of type 'Microsoft.Xrm.Sdk.OptionSetValue' to type 'System.IConvertible'.
    This error is coming from the timezone field and only happens when I have data in the field. Has anyone seen this?
    Thanks
    Rickard Norström Developer CRM-Konsulterna
    http://www.crmkonsulterna.se
    Swedish Dynamics CRM Forum: http://www.crmforum.se
    My Blog: http://rickardnorstrom.blogspot.se

    More info, the error occurs on pipeline stage 30 of the Book or Reschedule message and the same thing happens in CRM 2015. I've started a thread on connect with URL
    https://connect.microsoft.com/dynamicssuggestions/feedback/details/1128206/crm-2013-sp1ur1-cant-handle-the-timezone-field
    This must be rather new because I've tried it in CRM 2011 UR late and it did not occur there, I haven't tried CRM 2013 RTM though so I can't say if it's a CRM 2013 or a CRM 2013 SP1UR1 issue.
    BTW, the 2015 org was a complete vanilla so I've pretty much ruled out custom code as a culprit :)
    Regards
    Rickard Norström Developer CRM-Konsulterna
    http://www.crmkonsulterna.se
    Swedish Dynamics CRM Forum: http://www.crmforum.se
    My Blog: http://rickardnorstrom.blogspot.se

  • When I sort a column of figures, it sorts by the first digit. How do I get it to sort by the whole number?

    I have a column of numbers, Specifically: 5.2, 42.0, 25.5, 2.4, 11.8, 0.9, 0.5. Notice how it has sorted by the first digit, not the whole number. In other words 5.2 is ranked higher than 42, because 5 is larger than 4. What do I turn on or off to make it behave sensibly?
    Any answers would be appreciated.
    Martin

    Hi Martin,
    Are the cells formatted as Text (left aligned, as in Column B)?
    Data Format in Column C
    Column C will sort as Number.
    Regards,
    Ian.

Maybe you are looking for

  • SAP Business one 9.0 AddOn installer error

    Hi Experts, I have upgrade my SAP B1 from 8.82 to 9.0 PL 5. I have an addon also which is I compile with 9.0 DLLs. it is working fine if I direct connect by visual studio 2010 to any client 32-bit or 64 bit. But When I make an .ard file using B1DE 2.

  • "The disk you inserted was not readable by this computer" 10.9.3 - WD-500GB WD5000AADS

    Mac Book Pro MAC OS Extended(Journaled) Capacity:97GB Version-10.9.3 Hello Mac Fam, I recently purchased a HD-Enclosure (Insignia 3.0 desktop hard disk enclosure),since my WD 500Gig Hard Drive broke(power cable broke). Before the Hard Drive broke, it

  • Photoshop elements 10 still not responding.

    Ok, I thought it was solved but apparently not. It seems to be in the organizer when I have the issue.

  • My Airport is being screwy....

    I really have no idea what's going on. One day, just out of the blue, when I tried to join my airport network (Yes, my own one) it said "Error joining York street" then gave me "try again" and "Okay" choices. This has never happened to me before with

  • Autostart of Services

    Hi, I am new in oracle aqpps. I actually want to know that is we do single node installation OR multi node installation, after that, how would we identifiy different services to be started to at system startup? How we can identify service, for exampl