Issue rounding result to 2 decimal places

Good day all,
I currently have a format script to get the average of 10 fields on my form that also skips empty fields. Here is my current script:
// Initialize variables
var num = 0;
var sum = 0;
// Check input fields
for (var i = 1; i < 10; i++) {
var f = getField("Assesment_Rating" + i);
if (f.valueAsString) {
// increment the non-blank field counter
num++;
// add the field value to the running total
sum += +f.value;
// Calculate the average
if (num) {
event.value = sum / num;
} else {
// If fields are empty, so set to blank
event.value = "";   
As it currently works if I have a total of 1.4444444444444, that is what is displayed. I've tried a couple of Math.Round functions that give me "1.5" as a result which is not correct. I'm still learning so I may have tried a Math.Round function in the wrong part of my code, but cannot get the result I need.
Thanks in advance for your assistance!

That script should be a custom calculation script, which sets the field value. You can then set the format type to Number and two decimals.

Similar Messages

  • How do I round calculations to two decimal places (form-wide)

    Hi,
    I've created an order form where customers input the quantity of product they want to order and the form outputs the total due (including shipping and sales tax). Depending on user input, the resulting total sometimes contains more than two decimal places. How do I round calculations to two decimal places? Is there a way to do this form-wide?
    I'm new at using Acrobat for calculations. Any help would be greatly appreciated! Thanks...

    The above will affect the displayed value not the actual value of the field nor its value when accessed in another computation. This behavior may cause an error of 1 cent or more in the grand total or sales tax computation. If you want the the value and displayed value to be the same value you can use the following Validation script:
    event.value = util.scand("%,1 0.2f", event.value);

  • Price per unit is getting round off to two decimal places.

    Hi Gurus,
    In the Billing output, the Price per unit is getting round off to two decimal places.
    How can we avoid this or allow 4 decimal places for such cases.
    In the same pricing procedure, we have two pricing condition types PR02 and ZR01.
    When PR02 is being used,it doesnt rounds off Price per unit.e.g .578888 = .578888
    But when ZR01 is being used the system rounds off price per unit.e.g.578888 = .58
    Please suggest where is the setting for it.
    Thanks
    Montee

    Hi,
    Which currency you are using? If its INR, then it will do only for 2 decimal places.
    The solution for ur problem can be ractified by changing the scales :
    Also check OSS 80183
    Thanks,
    Raja

  • Round off to two decimal places

    hi
    i have a filed in it values are there i want to round off to two decimal places
    which is the function module for it please suggest
    regards
    Arora

    Hi Nishant Arora,
    Please check this code.
    DATA: N1 TYPE P DECIMALS 4 VALUE '0.0565',
               N2 TYPE P DECIMALS 2.
    MOVE N1 TO N2.
    WRITE: N2.
    Here the value is get rounded to 0.06.
    Rather than function modules you go with this. I think it is easier.
    Reward points if useful.
    Cheers,
    Swamy Kunche

  • Displaying results with a decimal place of two. Forcing decimal place.

    Hi there,
    Im writing a simple calculation device.
    You input one digit and press one of two buttons to multiply it by a certain number and then the result is displayed. The result is displyed hiding the result of the button you didn't press and visa versa.
    I am having a problem displaying the result with a constant two decimal place.
    I am using strings and thus don't know how to do this.
    Here is my code:
    import flash.events.MouseEvent;
    //restrict the input textfield to only numbers
    txtinput.restrict = "0-9";
    //restrict the input textfield to only two characters
    txtinput.maxChars = 6;
    // event listeners
    btnW.addEventListener(MouseEvent.CLICK, WHandler);
    btnC.addEventListener(MouseEvent.CLICK, CHandler);
    btnW.addEventListener(MouseEvent.CLICK, hideC);
    btnC.addEventListener(MouseEvent.CLICK, hideW);
    //functions
    function WHandler (e:MouseEvent):void
              //white calculation
              var answerW:Number = Number(txtinput.text) * Number(0.90);
              txtWResult.text = answerW.toString();
    function CHandler (e:MouseEvent):void
              //colour calculation
              var answerC:Number = Number(txtinput.text) * Number(0.99);
              txtCResult.text = answerC.toString();
    function hideC (e:MouseEvent):void
              //Hide colour result
              txtCResult.visible = false;
              txtWResult.visible = true;
    function hideW (e:MouseEvent):void
              //Hide white result
              txtWResult.visible = false;
              txtCResult.visible = true;
    After having a look online I have found these two resources:
    http://helpx.adobe.com/flash/kb/rounding-specific-decimal-places-flash.html
    and
    http://stackoverflow.com/questions/11469321/decimals-to-one-decimal-place-in-as3
    But I am confused when combining these techniques with strings.
    Any help would be greatly appreciated,
    Thanks in advance
    Mr B

    Use the toFixed() method of the Number class instead of the toString() method.  The result of it is a String with the number of decimal places you specify.
              var answerW:Number = Number(txtinput.text) * Number(0.90);
              txtWResult.text = answerW.toFixed(2);
              var answerC:Number = Number(txtinput.text) * Number(0.99);
              txtCResult.text = answerC.toFixed(2);

  • Rounding Doubles to Two Decimal Places

    Hi All,
    I've searched the archive and found a few different posts regarding restricting the number of decimal places in doubles. However they all suggest different methods, BigDecimal, NumberFormat etc.
    Which is the simplest method of rounding a number say 10.023445656 to 10.02?
    I tried using the java.text.NumberFormat but this turns the double into a string and I need the end result to be a double.
    Thanks

    Hi All,
    I've searched the archive and found a few different
    posts regarding restricting the number of decimal
    places in doubles. However they all suggest different
    methods, BigDecimal, NumberFormat etc.
    Which is the simplest method of rounding a number say
    10.023445656 to 10.02?
    I tried using the java.text.NumberFormat but this
    turns the double into a string and I need the end
    result to be a double.
    ThanksI ahve a small code that can do the work for u:
    import java.text.*;
    double format(double val, int dec){
        double multiple=Math.pow(10,dec);
        val=Math.round(val*multiple)/multiple;
        DecimalFormat df=new DecimalFormat("0.00");
        String format=df.format(val);
       double dval=Double.parseDouble(format);
       return dval;
    }//end of functionHope that helps!

  • Rounding off to two decimal places

    Hello,
    For simplicity, is there a method which will round off
    a double variable to two decimal places.
    Excample: if I have a result which equals 2.1999998
    and I want to display this as 2.20 in a TexTField.
    Any help would be much appreciated.
    Thanks

    If you are trying to do dollars and cents, I further recommend you use:NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance();
    String currencyOut = currencyFormatter.format(yourNumber);to format your numbers as they will give the correct precision for international currencies simply by setting the locale, and they will also automatically handle the currency symbols ($, DM FR, etc.)
    Doug

  • Bex: overall Result: number of decimal places

    Good day
    How to I change the number of decimal places for the "Overall result" in a query?
    Your assistance is appreciated.
    Cj Faurie

    Thanks for your response.
    The number format in properties for the KF (formula created in query) has been set to '0' decimal places. I also use the "Average of all values <>0" in the calculate results for the KF. If you use "Summation" then the decimal will apply, but not with the "Average .....".
    My "0CALMONTH" is in rows and results is based on this (set to 'never') as I want the Overall Result to display first as my chart is based on the OResult and not the individual figures.
    "This is the layout of my report"
    Territory     Overall Result    2007/02     2007/03    2007/03
    Boland       205.8333           21             242          355
    The "overall result' should display as '206'. Why does the 'decimal place' not apply to "Average of all v...."?
    Thanks
    Cj

  • Rounding Rule upto 3 Decimal Places in Tax Condition(SABRIX)

    Hi,
    We are Using SABRIX for Tax determination and need to round up Condition Type XR1- XR6 to round upto 3 Decimal Places.
    Do we need to To Change ALT Calc Type- 301306or Alt Cond Base Value -- 16  or have to change Currency  decimal Places in transaction OY04/OY03.
    Kindly Suggest.
    Thanks
    Amit

    Hi,
    Tax % for customer is decided in SABRIX, Where does TaX calculated?? In SABRIX or in SAP.
    Thanks
    Amit
    Edited by: AMIT GUPTA on Mar 31, 2010 10:54 AM

  • Result to two decimal places

    Hi I have the following code for currency conversion, now I want that when a converted currency result is for example 1.8 it displays 1.80 ie to two decimal places. how is this done? thanks
    private void converteurosButtonActionPerformed(java.awt.event.ActionEvent evt) {                                                  
    //Parse Euros as a double and convert to GBP.
        DecimalFormat df = new DecimalFormat("#,###.##");
        double gbp = (double) (Double.parseDouble(eurosTextField1.getText())) * 0.796345;       
        convertedeurosLabel.setText("� "+df.format(gbp));

      private static DecimalFormat format = new DecimalFormat("0.00");
      private String format(double value) {
        return format.format(value);
    // call  as
    format(2.999);

  • Rounding off to 2 decimal places

    Hi,
    I use "Double" for my calculations and since I am working with $$ ;-) I need to round it off at 2 decimal places. Any quick way to do this? or do I have to write some major code for that?
    Thanks

    This works for all the test cases. Try this
    import java.math.BigDecimal;
    import java.text.DecimalFormat;
    import java.text.NumberFormat;
    class RoundOff {
         public static void main(String args[]) {
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("173449.8"));
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("173449.98"));
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("-1.0"));
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("-1.0"));
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("-141.036"));
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("-00.1"));
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("-0.0"));
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("173449.98"));
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("173449.0.54"));
              //RARE EXCEPTIONS BUT WONT OCCUR
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("0125."));
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("0125.979.79E"));
              //RARE EXCEPTIONS BUT WONT OCCUR
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("173449.2354"));
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("173449.9874"));
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("173449.999"));
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("173449.999"));
         private static String formatPrecision(String s) {
              if (s == null || s.trim().length() == 0) {
                   return "0.00";
              try {
                   if (Double.parseDouble(s) == 0) {
                        return "0.00";
              catch (java.lang.NumberFormatException nfe) {               
                   return s;
              double d = 0.00;
              int ind = s.indexOf('.');
              String dec = "";
              if (ind > 0) {
                   dec = s.substring(ind);
                   if (dec.length() == 1) {
                        s = s.concat("00");
                        return s;
                   if (dec.length() == 2) {
                        s = s.concat("0");
                        return s;
                   if (dec.length() == 3) {
                        return s;
              if (ind == -1) {
                   return s.concat(".00");
              try {
                   d = Double.parseDouble(s);
                   BigDecimal bd = new BigDecimal(d);
                   bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP); //2 decimal places
                   d = bd.doubleValue();               
                   NumberFormat formatter = new DecimalFormat("0.00");
                   return String.valueOf(formatter.format(d));
              catch (java.lang.NumberFormatException nfe) {
                   return s;
    }

  • Round sum to 2 decimal places

    I've got this sum for a 'shopping cart' style design and want the prices to round to 2 decimal places
    I know I've got to put Math.round... in somewhere, but I just don't know
    Script:
    <script type="text/javascript"><!--
    function updateultra() {
    document.form.ultra.value = (document.form.sum1.value -0) * (1.79);  }
    //--></script>

    <script>
    function updateultra() {
        document.form.ultra.value = Math.round((document.form.sum1.value -0) * (1.79)); 
    </script>

  • Rounding numbers to 2 decimal places

    Hello programming community,
    I have the following code to round my answers to 2 decimal places:
    double roundedValue;
    DecimalFormat twoDForm = new DecimalFormat ("#.##");
    roundedValue = Double.valueOf(twoDForm.format(value));The code works great and what i expect it to do. When I pass in really big decimal numbers (2.55555668) it correctly rounds it (2.56) but when it rounds the number and the last decimal is a zero it does not display this. (if the number ends up rounding to 4.50 , i want it to display it this way but it ends up getting rid of the 0. )
    If anyone has any ideas for a way to fix this please let me know.
    Thanks.

    the-java-guy-needs-help wrote:
    i thought that my equation would be causing a problem and that i might need to do a cast -- I relized that this is not the problem
    for the type of string i am using the ("0.00")
    After trying various things the string does work if im just outputing it to the screen but i also use this rounding in a method that needs to return a double so i still need to convert it to a double.
    I have tried various ways of converting string to double (Double.parseDouble) and i tried one that involved a trim() but both methods drop the zero.You've got a basic misconception still going on here. If you convert it to a double, there is no such thing as a trailing zero -- it's meaningless since it only has meaning for a String representation of a double and not the intrinsic number itself.

  • Round float to 2 decimal place in the table

    Hi,
    One field in a table in my DB has float datatype.
    I insert some data into this table. The value read from a textbox I input as 0.02 for example. after insertion, I select the table and the field of the table shows the number as 0.0199999995529652
    Where did I do a wrong thing? how can I make it exactly as 0.02 in the table?
    Thanks.

    Hi there
    Float data types have known problems with precision, see
    here
    Since FLOAT and REAL are approximate numbers, you can run into all kinds of presentation / storage issues if you use them inadvertently. 
    They have their place, and if you are using scientific data that requires the properties of floating point numbers, th they are the right choice.  But in most cases, I think this is another evolutionary thing that happens accidentally when you upsize
    from Access.  You are much better off using DECIMAL or NUMERIC (which are functionally equivalent) unless you really know that you should be using FLOAT.
    You should consider changing the datatype to decimal or numeric if you need it to be more precise.

  • Convert rounded number into two decimal places

    Hi All,
    I have a Number 156 stired in a column having number(10,2);
    but i want to update it into 156.00......
    May be simple,,,,but how?
    Edited by: 887268 on May 29, 2012 10:04 AM

    Hi,
    156
    156.00
    156.0000000000000 and
    00000156.0000 are all the same NUMBER. There's nothing to convert.
    If you want to display a NUMBER in a certain way (e.g., with 2 digits after the decimal point) then use TO_CHAR, or have your front end format the column. In SQL*Plus, for example, you can use the COLUMN command:
    COLUMN   sal     FORMAT  99999.99
    SELECT  ename
    ,       sal
    FROM    scott.emp
    ;Output:
    ENAME            SAL
    SMITH         800.00
    ALLEN        1600.00
    WARD         1250.00
    JONES        2975.00
    ...

Maybe you are looking for

  • Eletronic Bank Statement.

    Hi friends, I Made a Global Settings for Eletronic Bank Statement, later I use FF.5 to Import it. After transacction run this message is dilplayed: <i>"(JBA_US_GENERAL 110) Branch is required for the document type ZE."</i> In Eletronic Archive dosn't

  • Video with quiz

    Hi all, I'm new to adobe captivate. I want to make a video but with quizzes in it. Which means that when I'm playing a video, it will stop at a certain time and a quiz will pop out. I've tried one myself however, it is not working. May I know if ther

  • How to make file smaller

    I need to make iphoto pictures smaller than 3mb...please help I need to upload into another program. thanks

  • Read a report where it will be almost impossible to get an iPhone 6 plus in stores tomorrow

    There is a report online that stores have been getting shipments in of iphone 6's throughout the day and many of them have said that they either don't have the 6 plus or have very little and not a variation of color or gb.  Your best bet is to try an

  • Transforming RAW file in TIF file

    I am new with Aperture and freshly back to MAC after 5 years with PC. I am trying my best to understand how it works. How do we transform a file from RAW to TIF ?