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>

Similar Messages

  • 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

  • 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);

  • 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

  • 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

  • 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

  • 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;
    }

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

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

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

  • Round to two decimal places...and keeping trailing 0

    Ok, I have done a search on rounding. So I made this function:
        private double round(double number){
           double d = Math.pow(10, 2);
           return Math.round(number * d) / d;
        }However, if I use a number like 3.59999, it returns 3.6. For what I am using it for, I need it to return 3.60. Any ideas? Thanks.

    You normally only format for display! You seem to be wanting the default format to show 2 decimal places. This makes no sense. Internally a number(double or float) doesn't know about decimal places so how can the default format know you want 2 decimal places?
    For the most part you only need to worry about decimal places when you print a number using the DecimalFormat class.
    There are times when you might want to round values to 2 decimal places before doing more calculation. I have only met this when adding monetary values when it is important that a column total equals the sum of a displayed column values. In this case one uses something like the technique you originally proposed to round values before summing them. You then use DecimalFormat to display the values.

  • Rounding to two decimal places in BPC/NW

    Hello,
    I am dealing with the task to round values to two decimal places. I have found some discussions in BPC-MS where the statement ROUND should work in logic. Unfortunately I am not able to make it work in the NW version.
    Isn't there also a parameter in the appset or application administration which would cut the numbers only to two decimal places (this task would be also a possible solution for us).
    Thanks for any help
    Jan

    Hello Pravin,
    the second import worked fine. I realized that the class has changed to ZCL_BPC_SL_ROUND.
    I debugged the class and noticed that the parameter it_cv is not filled at all. Therefore the program ends before starting the rounding procedure. Here is the part of the code:
    Take CV into account
      clear l_success.
      loop at it_cv into ls_cv.
        clear l_val_string.
        loop at ls_cv-member into l_member.
          if sy-tabix eq 1.
            l_val_string = l_member.
          else.
            concatenate l_val_string l_member into l_val_string separated by ','.
          endif.
        endloop.
        if l_val_string ne space.
          l_success = add_dim_restriction( i_param = l_val_string i_dimension = ls_cv-dimension i_clear = abap_true ).
          if l_success eq abap_false.
            concatenate 'Failed to successfully add Dimension' ls_cv-dimension into l_log_msg
            separated by space.
            cl_ujk_logger=>log( l_log_msg ).
            cl_ujk_logger=>log( 'Exiting Round Method' ).
            cl_ujk_logger=>empty_line(  ).
            raise exception type cx_uj_custom_logic
              exporting messages = et_message.
            exit.
          endif.
        endif.
      endloop.
      if l_success eq abap_false. exit. endif. - here the program exits and therefore doesn't do any rounding.
    If I comment this part the system rounds correctly but runs on all records in the cube which degrades performance a lot.
    Could you please advice further if it is possible to restrict the data region only to the submitted data?
    Best regards
    Jan

  • Rounding to 1 decimal place.

    Hello again.
    I have a method called "findTheAverage" which takes in an array of integers as a parameter and then calculates and returns the average as a float.
    What I want to do now though is create another method called "roundTheAverage" which takes in the float average variable from the previous method, rounds it to one decimal place, and then returns it as a float called roundedAverage.
    Could anybody help me in achieving this?
    Thanks.

    I'm fairly new to Java, hi.
    Oh I know all about you.
    I'm trying to write a method which takes in a float
    called "number" and then returns this float to two
    one decimal places called "roundedNumber".
    This is not the way this works. You have to write your own code.
    >
    Could you type me the code that I'd need to do this
    perhaps?
    Nope.
    It's a pretty simple problem I think, and it's
    wasting an enormous amount of time figuring it out.
    You are right on both counts. It is very simple and you are wasting alot of everyones time.
    >
    thanksAPI Application Programming Interface
    Javadoc API
    In context for this site means the documentation for the basic packages that make up the core Java API.
    I provided a link earlier to the Javadocs for java.text.DecimalFormat
    If you can't figure it out you need to HIRE A TUTOR.

Maybe you are looking for