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;

Similar Messages

  • Calculator with two numbers

    Dear Forum
    Im working a calculator with a textfield. It can calculate a if a enter only one number, but when i try to enter two or three doesnt work. I have test several codes but they are not working at all. Could any someone give me a hand. Please se te attach file.
    var numeroEntrado = "";
    var campoUno:int = 125;
    var campoDos:int = 20;
    var elResultado1 = 0;
    var elResultado2 = 0;
    proteinas.text = "125 grs.";
    colesterol.text = "20 mml.";
    colesterol.backgroundColor = 0x9999FF;
    textoColesterol.backgroundColor = 0x9999FF;
    numeroPorciones.maxChars = 3;
    numeroPorciones.restrict = "0-9";
    btn.addEventListener(MouseEvent.MOUSE_UP, suma);
    function sienteTecla(event:KeyboardEvent):void {
        if (event.keyCode == 48) { numeroEntrado = 0; }
        if (event.keyCode == 49) { numeroEntrado = 1; }
        if (event.keyCode == 50) { numeroEntrado = 2; }
        if (event.keyCode == 51) { numeroEntrado = 3; }   
    function suma(evt:MouseEvent):void{
            proteinas.text = "";
            elResultado1 = Number(campoUno) * Number(numeroEntrado);
            proteinas.text = elResultado1 + " grs"; 
            colesterol.text = "";
            elResultado2 = Number(campoDos) * Number(numeroEntrado);
            colesterol.text = elResultado2 + " mml" ;
            numeroPorciones.text = ""
    thanks
    IN

    It's difficult to say without understanding your intent.
    I don't see where you event listener for sienteTecla  is being assigned.
    If numeroEntrado is supposed to be numeroPorciones value (a guess) then perhaps you could just do something like this:
    function suma(evt:MouseEvent):void{
        if (numeroPorciones.text!="") {
            proteinas.text = "";
            elResultado1 = Number(campoUno) * Number(numeroPorciones.text);
            proteinas.text = elResultado1 + " grs";
            colesterol.text = "";
            elResultado2 = Number(campoDos) * Number(numeroPorciones.text);
            colesterol.text = elResultado2 + " mml" ;
            numeroPorciones.text = ""

  • Calculations with floating numbers

    I am doing some calculations within an application have have found the following happens:
    System.out.println("calculation: " + (22.0*4.4));
    results in the output:
    calculation: 96.80000000000001
    Why is this? I understand that rounding has to happen on sum figures, but not these two - how can I get the 'proper' result of 96.8??
    Thanks

    import java.math.BigDecimal;
    public class Test {
        public static void main(String[] args) {
            double d1 = 22.0;
            double d2 = 4.4;
            System.out.println(d1);
            System.out.println(d2);
            // with Java 5.0 printf
            System.out.printf("%.1f%n", d1 * d2);
            // With BigDecimal
            BigDecimal bd1 = new BigDecimal(d1);
            BigDecimal bd2 = new BigDecimal(d2);
            System.out.println(bd1);
            System.out.println(bd2);
            BigDecimal product = bd1.multiply(bd2);
            BigDecimal scaled = product.setScale(1, BigDecimal.ROUND_HALF_UP);
            System.out.println(scaled);
    }Cheers, Neil

  • Need help with rounding numbers in Java

    I finally have this program to where it needs to be except for one thing. The variable "freetime" isn't showing any kind of output in the applet. The variable sum and freetime are both called at the start of the program, and have equations to figure out the output for them, but only sum shows an output. I tried using brackets as opposed to multiple parentheses. What can I do to fix this so that there is an output? I was thinking of using something to round up the result, but I can't figure it out. Can anyone help?
    import java.awt.*;
    import javax.swing.*;
    public class FinalLab extends JApplet{
    String firstNum, secondNum, thirdNum, fourthNum, fifthNum;
    int personal, family, school, work, sleep, sum, freetime;
    public void init()
    String firstNum, secondNum, thirdNum, fourthNum, fifthNum;
    firstNum = JOptionPane.showInputDialog( "Enter total personal hours." );
    secondNum = JOptionPane.showInputDialog( "Enter total family hours." );
    thirdNum = JOptionPane.showInputDialog( "Enter total school hours." );
    fourthNum = JOptionPane.showInputDialog( "Enter total work hours." );
    fifthNum = JOptionPane.showInputDialog( "Enter total sleep hours." );
    personal = Integer.parseInt( firstNum );
    family = Integer.parseInt( secondNum );
    school = Integer.parseInt( thirdNum );
    work = Integer.parseInt( fourthNum );
    sleep = Integer.parseInt( fifthNum );
    sum = (personal + family + school + work + sleep);
    freetime = ((168-sum)/168)*100;
    public void paint(Graphics g) {
    super.paint( g );
    g.drawRect( 15, 10, 270, 20 );
    g.drawRect( 15, 35, 270, 20 );
    g.drawRect( 15, 60, 270, 20 );
    g.drawRect( 15, 85, 270, 20 );
    g.drawRect( 15, 110, 270, 20 );
    g.drawRect( 15, 135, 270, 20 );
    g.drawRect( 15, 160, 270, 20 );
    g.drawString( "Personal hours: " + personal, 25, 25);
    g.drawString( "Family hours: " + family, 25, 50);
    g.drawString( "School hours: " + school, 25, 75);
    g.drawString( "Work hours: " + work, 25, 100);
    g.drawString( "Sleep hours: " + sleep, 25, 125);
    g.drawString( "Total hours: " + sum, 25, 150);
    g.drawString( "Free time: " + freetime, 25, 175);
    }

    I am guessing that you really meant that you are seeing "Free time: 0" instead of what you said, which was that it wasn't showing any kind of output. (Your whole terminology is weird, you don't "call a variable" just for example.) If that's the case, it's because you are using integer division. You'll find that 27/168, for example, gives zero. I don't know why you are multiplying by 100 in your calculation and doing the division, perhaps you meant to return the free time as a percentage (in which case your output should say that), but since you are doing that you could do it this way:((168-sum)*100/168)Then you are doing 2700/168, which produces a reasonable number.

  • How to round numbers in java?

    hey everyone. just wondering how i can round my final answer which is "repayment" located on the last line to the nearest whole value. thanks :) this is my code:
    //Conversion and Calculation
    principle = reader.readDouble("Enter Loan Amount: ");
    interestRate = reader.readDouble("Enter YEARLY interest rate: ");
    convertedRate = interestRate / 100;
    monthlyRate = convertedRate / 12;
    timePeriod = reader.readDouble("Enter the number of years for the repayment: ");
    convertedPeriod = timePeriod * 12;
    //Calculation Monthly Repayment Amount for a fixed number of years
    topHalf = Math.pow((1+monthlyRate),convertedPeriod);
    bottomHalf = (Math.pow((1+monthlyRate),convertedPeriod)-1);
    fraction = topHalf / bottomHalf;
    repayment = principle * monthlyRate * fraction;
    writer.println ("Fixed Monthly Repayment Amount = $" +repayment);                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Good point: Klue2k, don't forget about the negative
    case.Yes, never forget about the negative case. Your
    solution doesn't work with negative numbers!
    And by the way, if you had a little bit more of the
    good old klue2k, you wouldn't be embarassing yourself
    in this way.I think you're confusing me with somebody who give a 5h!t.

  • Spawning pages with page numbers "page 1 of 1"

    I'm using a calculation script to define "page 1 of 2" in a form. The script is as follows.
    //set the page number to number 1
    this.pageNum = 1;
    //use the page of page format
    event.value = "Page " + (event.target.page+1)+" of " + (this.numPages);
    This works fine, however, when I start spawning pages the numbers get mixed up. For example, if I spawn one page, the "page 1 of 1" on page one changes to "page 1 of 2." On page two, it reads "page 0 of two." I just can't seem to get the "page n of n" to work with spawned pages. Any suggestions would help.
    Thank you

    For each page's field number page you need to go to that page in the calculation script. You could also turn off calculations during the spawning of the pages and then turn it back on and recalculate the form.
    // code to spawn template;
    // turn off automatic calculation;
    this.calculate = false;
    var t = this.templates;
    var T = t[0];
    T.spawn(this.numPages, true);
    // trun automatic calculation back on;
    this.calculate = true;
    // force recalculation;
    this.calculateNow();
    // end spawn template;
    // custom calculation script for numbering pages;
    var cField = event.target.name;
    var aField = cField.split(".");
    if(aField.length > 1) {
    // get page number for form field from field name & go to that page;
    this.pageNum = aField[0].substr(1,1);
    // update field's value;
    event.value = (this.pageNum + 1) + " of " + this.numPages;
    // update field's default value;
    event.defaultValue = event.value;
    // end custom calculation for numbering pages;

  • Calculating with attributes occurs problems in aggregation ...?

    Hi Gurus, I have a question concerning the calculation with attributes:
    I have created variables (as replacement path) based on a product attribute. The variables (with the attribute value) do work properly and I get the right numbers in the lowest hierarchy level.
    Problem: within my hierarchy structure the query does not aggregate but reports errors ("X") in the upper hierarchy levels. How can I solve this problem?
    Thank you for answering.
    Greetings from T. Duong

    Hi, I already have tried this but it didn't lead to the required result.
    Still thank you for answering. I have seen in SAP Help that the options in extend properties might solve similar problems ... still mine cannot be solved by this. The problem is not the attribute value itself, as I found out.
    I have another thread here, where I defined my problem that occurs due to a formula collision between a structure and a hierarchy.
    Thank you.
    Best regards
    T. Duong

  • Working with Large Numbers

    Hi there,
    I am currently doing a school assignment and not looking for answers but just a little guidance.
    I am working with large numbers and the modulo operator.
    I might have some numbers such as :
    int n = 221;
    int e = 5;
    int d = 77;
    int message = 84;
    int en = (int) (Math.pow(message, e) % n);
    int dn = (int) (Math.pow(en, d) % n);Would there be a better way to do this kind of calculation. The dn value should come out the same as message. But I always get something different and I think I might be losing something in the fact that an int can only hold smaller values.

    EJP wrote:
    It might make sense in some contexts to have a positive and negative infinity.
    Yes, perhaps that's a better name. Guess I was harking back to old COBOL days :-).(*)
    But the reason these things exist in FP is because the hardware can actually deliver them. That rationale doesn't apply to BIgInteger.Actually, it does. All I'm talking about is a value that compares higher or lower than any other. That could be done either by a special internal sign value (my slight preference) or by simply adding code to compareTo(), equals() and hashCode() methods that takes the two constants into account (as they already do with ZERO and ONE).
    Don't worry, I'm not holding my breath; but I have come across a few situations in which values like that would have been useful.
    Winston
    Edited by: YoungWinston on Mar 22, 2011 9:07 AM
    (*) Actually, '&plusmn;infinity' tends to suggest a valid arithmetic value, and I wasn't thinking of changing existing BigInteger/BigDecimal maths (except perhaps to throw an exception if either value is involved).

  • How to paste calculated values from Numbers?

    When I copy calculated values from Numbers and paste into a table in Pages, I get an image like the one below.  Non calculated values paste fine.
    To get around this issue, I paste the calculated values into TextWrangler, then copy from there and paste into Pages.  Is there a way to go directly from Numbers to Pages with calculated values?

    Hi 4th Space,
    I you are pasting into a table in Pages, follow Jeffs instructions.
    I you are not pasting into a table, this works. Copy the cells in Numbers. Go to your Pages document and under the Edit Menu > Paste and Match Style. It works like Paste Values.
    Ian.

  • How to disable certain form fields from a calculation with a check mark fields.

    How to disable certain form fields from a calculation with a check mark fields.
    In Canada we have to taxes
    I create a form that calculate them to a total
    I need to be able to turn off any of those to taxes to participate to the calculation and their visibile field should become 0
    I was thinking using a checkbox (when checkbox is on (Yes) the tax is calculated, Not ticked (Off) the tax is not calculated and the visible field should show 0 or nothing....
    I really need help on this one — I’m a complete newbie....
    Remark that the second tax is calculated on the sum of what the first tax add (first tax is pan-canadian tax (all provinces).
    The second tax is never use alone (Quebec only (on top of the Canadian one)
    Sometime for outside Canada sell - No tax at all is calculated....
    What should I do?

    I want to tank you to help, really appreciate —>
    This is the code and order... I just trow the checkbox in there (they have, so far, no purpose...)
    The code use is
    var a = this.getField("pricehorstx");
    event.value = Math.round (a.value * 7.25) / 100
    I guess -If the checkBox are check - The tax should be calculate — If “Off” the tax should be not calculated and PriceHST and /or PriceQST should show zero or be empty — The HST is always calculated in Canada, but the QST is added only in Quebec.
    I need to turn both to Zero for international sale.
    Message was edited by: Chacapamac

  • Rounded Numbers Dont Add Up

    I have a user who is complaining that the numbers on her report don't add up to the total that's printed at the bottom. I haven't seen a sample of this yet but I wanted to run this by you guys and see if this code makes sense.
      function() {
        NumberFormat nf = new DecimalFormat("#,##0.00");
        double total = 0D;
        for (...) {
          double d = Math.random();
          total += round(d);
          print(nf.format(d));
        print(nf.format(total));
      double round(double d) {
        return (double)(Math.round(d*100)/100D);
      }Is my round() sound?

    I have a user who is complaining that the numbers on
    her report don't add up to the total that's printed at
    the bottom. This could be a problem with the user in that they don't understand numerics.
    Or it could b a problem with you in that you do not understand the problem domain.
    Floating point numbers are always inaccurate. It doesn't matter whether humans or computers do this. That is because floating point numbers (when used correctly) are an approximate measure of something which can not be measured exactly.
    For example a pound of hamburger might be marked as weighing 1.01 pounds. The inaccuracy is in that it might actually weigh 1.01015678 pounds (but is unlikely to weigh even that.) There is no way to get the exact weight.
    Now if that is your situation then it is problem with the user - the user doesn't understand numerics and the inherit inaccuracies.
    And it would probably be a bad idea for you to "fix" it for one user, when other users are expecting correct approximations.
    (One way to fix this is to 'fiddle' with the numbers that make up your sum. Adjust one so everything 'looks' right.)
    On the other hand maybe it is your problem. For example money. Money is not a floating point number, because money is always exact. Even when caculating interest it is always exact. You will never end up with a partial penny in your savings account, no matter how the interest rate is computed.
    And since money is accurate a floating point number is not necessarily the best way to represent it. Care must be used in doing so. As a previous poster suggested the BigDecimal class can be used.
    Or if your numbers are small then simply convert the money to integers by multiplying by 100 and rounding and then compute everything using that. And simply reformat the integer values so they look like floating point numbers rather than integers when you print them out.

  • 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
    +

  • How to round numbers

    assume variable a is 4.647 and i want to convert this to 4.5 . how can i round numbers like this. Is there is a predefined method in java to achive this.

    I don't think java.lang.Math.round() will do what the original post asked for, since it rounds to the nearest long number. So you still would have to write your own method to round 4.647 down to 4.5.

  • How to round numbers using javascript in Adobe Acrobat Pro?

    How to round numbers using java script in Adobe Acrobat Pro?
    For example:
    1.2 becomes 1.0
    1.7 becomes 2.0
    Thank you.

    Assuming you've already set the field to a Number format category and limited it to one digit to the right of the decimal, you can use the following custom Validate script:
    // Custom Validate script
    event.value = Math.round(event.value);
    More info: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/roun d

  • I have 1 apple id, 2 5S iPhones with separates numbers and both ring when I get a call on one of the numbers. How do I switch that of ?

    I have 1 Apple ID, 2 5S iPhones (1 private/1 work) with separates numbers and both phones ring when I get a call on one of the numbers. How do I switch that of ?

    I realize that my wife could make her own iTunes account; however, she's been using mine for about 2 years now and this hasn't been an issue.  I guess with the Family Sharing she can have access to all of our music and apps now with her own account. 
    I'll have to see if unchecking our emails resolves this issue.

Maybe you are looking for