Effective method to round double on 0.05

I have a question on double rounding on 0.05

As much as I know there is no class method that is able to do this. To reach this round, I have the following code:

Example:

164.67-> 164,70

173,33 - > 173,35

-> 0.05 0.02

 double calculatedQuantity = 0.0;

  // Formula to calculate the average working hours in a month
  int totalWeeksInYear = 52;
  int totalMonthsInYear = 12;

  calculatedQuantity = (quantity * totalWeeksInYear) / totalMonthsInYear;
// Round the 2 decimals
  calculatedQuantity = calculatedQuantity * 100;
  calculatedQuantity = Math.round(calculatedQuantity);

  //The rounding has to be on 0.05 in the benefit of the employee. Use modulus to get a 0 or 5
  while(calculatedQuantity%5!=0){
  calculatedQuantity = calculatedQuantity + 1;
  }


  calculatedQuantity = calculatedQuantity/100;

  calculatedQuantity = calculatedQuantity/100;

It works but I do not have the feeling that it is effective.

Any suggestions would be welcome.

Kind regards

Hans

Hello Hans,.

Try to multiply by 20 and round up (java 'ceiling' I mean), then dividing by 20.

Something like:

calculatedQuantity= (double) Math.ceil(calculatedQuantity * 20.0 ) / 20.0;

Kind regards

Rajen

Tags: Java

Similar Questions

  • Effect on Res when double for printing?

    SCENARIO:

    I build graphics for a large screen wall, too big for Illustrator to manage in real size.

    So I work half the real and at 150 dpi dimensions.  I want the final file for printing to be actual size (obviously) more be 300ppi.

    A company will do this, and because I'm not sure what they are doing to double my file for printing, I don't know what the effect will be.

    QUESTIONS RELATING TO THE:

    (1) if I build a half size, 150 dpi-vector graphics, when it doubles, it will be actually at 300 ppi?

    (2) if I add pictures (raster) to 300 ppi to the artboard 150 dpi, they maintain 300 DPI when the final file is doubled at their end, or will it be bumped up 600 dpi?

    HELP APPRECIATED!

    Dan,

    First of all, you should be aware that resoultion necessary/appropriate depends on the viewing distance. At twice the distance, half the resolution will appear the same.

    You can see it as a question of viewing angle. In the same angle of view, a last image with a number of pixels x pixels will appear identical, whether the size of the screen or on a building across the street.

    Second, the resoultion necessary/appropriate depends on the real work and the printing method. Art online requires a much higher resolution than the other graphic works and forget about 300 PPI as any value standard.

    The resolution in printing of vector illustrations depends entirely on the ability of the printer settings.

    Art of raster, like a photo, has a size in pixels x pixels so the resolution is inversely proportional to the size.

    (1) if I build a half size, 150 dpi-vector graphics, when it doubles, it will be actually at 300 ppi?

    N ° it will be independent, just a function of the printer (setting).

    (2) if I add pictures (raster) to 300 ppi to the artboard 150 dpi, they maintain 300 DPI when the final file is doubled at their end, or will it be bumped up 600 dpi?

    Neither. It will be reduced by half when the size is doubled, in this case ending with 150.

    And someone else can say.

  • What is an effective method to create presets?

    Hi all

    I am trying to create presets for my VI and I would like comments from other people who were created pre-defined methods.  I saw this post and saw that it was possible to create a "Preset" pre defined pretty easily.  It is one, but I need to update my presets on the fly.  Basically I want through four servos pulsewidth at a certain position.  However, there will be a lot of different positions (~ 20) I need them to be at, and try to arrest the code and constants looks like it will be extremely difficult for each preset.  I would like to create a predefined method that would take the servo location and store it somewhere so I can load it again later.

    One idea I had was to create a txt file and store the pulsewidth of each servo.  This way I could replace the file and read the file at any time.

    I searched in the structures of the event, but that seems like it will go with the idea of making pre made presets.

    Any help would be gladly appreciated.

    Thank you

    Matt

    If you have just 20 positions, which will never change you can use Enum control connected to a case structure (all this in awhile put in loop).  If the Enum control value changes, select the box structure that contains the values to correct pulswidth.

    If your positions could change overtime, an external file would be a good way to do.  Look at the Configuration files.  You can write an article for each position.  In each section, you will store the 4 values of pulsewidth you need.

  • The most effective method to add Gaussian blur to the background of the Interview with two people

    I have MXF clips of an interview with two people with a décor of forest behind the two subjects. I want to add a Gaussian blur on the bottom between the two people who are sitting and separated by about 6 inches. I'd be able to do this now in 2014 PR, except track masks do not work as there seems to be a bug. I've never used AE and Mocha looks like a tracking method possible. The manual speaks using a compressed JPG of sequence, then use your original film when you apply the data. This sounds like the way to go, but I do not know how to apply the data originally from the film. I know how to apply a blur and a simple mask followed in AE, but it does not follow the outline of the person and blurs the second person. If followed PR mask worked, I duplicate the layer and add a mask of garbage that would cut off the other person in each of the two layers.

    I intend to learn AE, but has a deadline this week to get this infomercial delivered to the customer. Thus, detailed instructions would be greatly appreciated.

    Thank you, Rob

    According to your film, the Roto Brush tool can be a good choice to separate people from the background.

  • effective method for searching for my computer and its peripherals

    I am very dissatisfied with the tools at my disposal to search for my computer. I'm looking for another product, because Microsoft developers seem to have as objective search of his computer a very difficult task.

    So what third-party products are out there for the research and management of research on his computer?

    Here is an example of a task, I want to perform. I have a directory with pdf files and word files. I have a sentence and I want to find all files to see which files have this single sentence? It is a basic task simple, I'm sure that almost everyone would like to do at some point. This simple task was made more difficult with each subsequent version of windows.

    Here are some tasks I want to do like all the time.

    Look for file names and not the content of the files. searching content of files in file types. Search files with a certain creation, date of modification. all these things are hidden by users and which must be very complex I have a suite of wire run.

    You need this search filter from Adobe installed so that the indexer will gain the ability to 'see' inside these files: http://www.adobe.com/support/downloads/detail.jsp?ftpID=5542

  • The most cost-effective method?

    I'm a marketing department of a professor who sometimes works from home and has occasional help from the other three. Right now, we have three products under individual license, but with the cloud is more fiscally responsible of owning an operating licence with several places or continue with individual programs? I can't find how many seats is provided with the cloud of the team.

    GeoBuffy These links should give you an idea of CC team (CCT) and should answer your questions.

    http://www.Adobe.com/in/products/creativecloud.html

    http://www.Adobe.com/in/products/creativecloud/FAQ.html#CC-teams

  • AE never use 'double precision FP64' calculation of Visual effects?

    I'm trying to find out if after effects never really use double precision calculate what whether or not. I know the basis of coding video is really ever use it, but I wonder if the particle effects benefit from double precision or if it's mostly to single precision.

    I am currently using a GTX black Titan, which has a good amount of double precision performance, but I don't know if I ever really use it. I'm looking to the new Titan X, which essentially replaces the power of calculation of double-precision with even more unique precision. I especially to create the content of the game in real time and can always benefit from the upgrade of single precision performance, but I also use After effects a good amount and won't lose boosts performance in it. I can get more benefits on the Titan X because that all rendered I do generally is through converters of cpu and no gpu converters, but I do not know what changes After Effects has achieved since CS6.

    Totally irrelevant. Effects like Particle World are not the same hardware accelerated, so what might even be the point on single-precision and double-precision? And for all purposes useful, it is even irrelevant if that were the case - many pixel operations and position related calculations are quantified / integer for which single precision is sufficient. Double-precision really only countries out for complex vector operations where rounding errors for example can mess with for dynamics or similar collision detection.

    Mylenium

  • Help with writing/reading-key key ini files (double) and defined accurarcy

    Hello

    in a pop-up window, the user can insert a digital double value.

    This value is stored in an ini file using the writing-key-vi with Type = double. Works very well.

    What should I do to adjust the values after the decimal point?

    If the user inserts 1 532 so I want to round to two digits after the decimal point and save it. (-> 1.53)

    THX

    I don't know how LV treats different decimal separators (for example, the comma instead of point), I guess that's "just works" according to settings system locale.

    A few options are available as follows...

    The function write key has an entry of 'precision' which will set the number of decimal places to save the DBL to (in your case, set it to 2):

    If you use a number field, you can set the 'increment' property to 'force close' to keep them out in more accurately than is available:

    The obvious method for rounding of the entry is to scale the number, rounded to the nearest integer and then divide again to limit the accuracy:

    I couldn't see anything in the digital pallets / math that does this.

  • The rounding value

    How can I round the double value of a not given numbers fraction, Say for example: my double is 10.222222222 for this issue, I want only 10.22 and 10.899999 for that 10.90

    How can I do this task?

    I wrote getDoubleValue (double) method that rounds the fractional pats

    public static double getDoubleValue (double value) {}
    Dim str As String = String.valueOf (value);
    int index = str.indexOf ('.) ', 0) + 1 ;
    String integer = str.substring (0, index-1);
    Decimals of string = str.substring (index);
    If (decimal.length)< 4)="">
    Returns the value;
    }
    isPre boolean = true;
    int i;
    for (I = decimal.length () - 1; i > 3; i-) {}
    Val As Char = decimal.charAt (i);
    If (val > = '5' & val)<= '9')="">
    isPre = true;
    } else {}
    If (isPre & val == '4') {}
    isPre = true;
    } else {}
    isPre = false;
    }
    }
    }
    decimal = decimal.substring (0, i);
    If {(isPre)
    int val is (Integer.parseInt (decimal) + 1);.
    {if(Val>=1000)}
    Integer = String.valueOf (Integer.parseInt (Integer) + 1);
    decimal = '0 '.
    } else {}
    decimal = String.valueOf (Integer.parseInt (decimal) + 1);
    }
               
    }
    return Double.parseDouble (integer + "." + comma);
    }

  • Math.Round () and Math.Random)

    Hello

    Do we have the equivalent methods in J2ME for Math.round () and Math.Random ()? I could not find in Java.util.Math or net.rim.device.api.Math

    Thank you.

    Reshma

    @ JavaMEUser, you can write your own class of math for your application, use the following code...

    public static int round(float f)  {     return (int)(f + 0.5F);   }public static long round(double d) {                return (long)(d + 0.5D);   }
    

    Thank you!

  • Error java.lang.ArithmeticException: required rounding

    Hi all.

    I got the error "java.lang.ArithmeticException: required rounding ' in the following line

    String DividendAmountStr = String.valueOf (new BigDecimal (DividendAmount) .setScale (2));

    What should be the problem?

    -Barros

    It is possible was not so perdantic Java 1.3. Also, it is easy to write some prgrams with bugs that just happened to work the way they are used. Do things a little differently reveals the bug.

    The problem is the use of new BigDecimal (double). This gives a faithful reproduction of the double value underlying. Many methods that convert double to another type allow a small rounding in double error, this constructor is not.

    Even a simple value like 0.1 has a small mistake of rounding of type double. Normally, it is not clear, with BigDecimal is.

    double d = 0.1;
    System.out.println("d= " + Double.toString(d));
    BigDecimal bd = new BigDecimal(d);
    System.out.println("bd= " + bd);
    BigDecimal bd2 = BigDecimal.valueOf(d);
    System.out.println("bd2= " + bd2);
    

    prints

    d= 0.1
    bd= 0.1000000000000000055511151231257827021181583404541015625
    bd2= 0.1
    

    As you can see the second method for the conversion of a double is not this round question for this value. This could be a temporary option and it might work most of the time, but use setScale() with a rounded option will work every time.

  • ASA double authentication only

    My company is currently testing on authentication dual factor for specific users. We use to authenticate, SecureAuth keys and an existing AD server, which is also used to authenticate for our other groups VPN. For this reason members of the auth group double can authenticate current VPN groups using only their letters of credence to AD.

    Is the way for me to configure this group only being able to obtain VPN access if they go through the method of the double factor?

    Essentially if the double group auth users connect via the Group dual auth in anyconnect, they will not be able to establish a vpn connection what do I try to install.

    Any contribution is appreciated!

    Have allowed all users to AD authenticate are only the first A of AAA.

    You can control what they are allowed to make (or connect to) based on the name belonging to a group or user.

    You may need to make a new ad group for everyone, but they and make membership in that group a requirement for the default profile. Do another group of ads for new users of two-factor and make membership in this group a requirement for this new profile.

  • Need to find a good method

    Hi all

    I have written the following code, but I wonder that there is an effective method available for this kind of work, I appreciate if someone suggest me a good method.

    I have the following code.

    Code example

    BEGIN
    FOR (IN) j
    SELECT F_RS, V_RS, C_RS, TRANS_TYPE_CD, trans_amt, low_id, J_ID
    XYZ
    WHERE low_id = 123
    )
    loop
    IF j.TRANS_TYPE_CD = 'F' and j.trans_amt > 0 THEN

    UPDATE XYZ jou
    F_RS = j.TRANS_AMT, VALUE
    V_RS = 0,
    C_RS = 0
    WHERE jou.low_id = j.low_id
    and played. TRANS_TYPE_CD = j.TRANS_TYPE_CD
    and trans_amt > 0
    and J_ID = j.J_ID;
    ELSIF j.TRANS_TYPE_CD =' it and j.trans_amt > 0 THEN

    UPDATE XYZ jou
    C_RS = j.TRANS_AMT, VALUE
    F_RS = 0,
    V_RS = 0
    WHERE jou.low_id = j.low_id
    AND played. TRANS_TYPE_CD = j.TRANS_TYPE_CD
    and trans_amt > 0
    and J_ID = j.J_ID;
    ELSIF j.TRANS_TYPE_CD in ('TER', 'FED') and j.trans_amt > 0 THEN

    UPDATE XYZ jou
    V_RS = j.TRANS_AMT, VALUE
    F_RS = 0,
    C_RS = 0
    WHERE jou.low_id = j.low_id
    AND played. TRANS_TYPE_CD = j.TRANS_TYPE_CD
    and trans_amt > 0
    and J_ID = j.J_ID;
    -----------
    ELSIF j.TRANS_TYPE_CD = 'F' and j.trans_amt < 0 THEN

    UPDATE XYZ jou
    F_RS = j.TRANS_AMT, VALUE
    V_RS = 0,
    C_RS = 0
    WHERE jou.low_id = j.low_id
    and played. TRANS_TYPE_CD = j.TRANS_TYPE_CD
    and trans_amt < 0
    and J_ID = j.J_ID;
    ELSIF j.TRANS_TYPE_CD =' it and j.trans_amt < 0 THEN

    UPDATE XYZ jou
    C_RS = j.TRANS_AMT, VALUE
    F_RS = 0,
    V_RS = 0
    WHERE jou.low_id = j.low_id
    AND played. TRANS_TYPE_CD = j.TRANS_TYPE_CD
    and trans_amt < 0
    and J_ID = j.J_ID;
    ELSIF j.TRANS_TYPE_CD in ('TER', 'FED') and j.trans_amt < 0 THEN

    UPDATE XYZ jou
    V_RS = j.TRANS_AMT, VALUE
    F_RS = 0,
    C_RS = 0
    WHERE jou.low_id = j.low_id
    AND played. TRANS_TYPE_CD = j.TRANS_TYPE_CD
    and trans_amt < 0
    and J_ID = j.J_ID;
    End if;
    END loop;

    End;

    Appreciate your help

    Seems something also (NOT TESTED).


    merge into xyz jou

    using (select f_rs, v_rs, c_rs, trans_type_cd, trans_amt, low_id, j_id

    XYZ

    where low_id = 123

    and trans_type in ('F', 'C', 'B', 'FED')

    - and trans_amt! = 0

    ) j

    on (jou.low_id = j.low_id

    and jou.trans_type_cd = j.trans_type_cd

    and jou.j_id = j.j_id

    )

    when matched

    then update

    Set f_rs = case when j.trans_type_cd = 'F' and sign (jou.trans_amt) = sign (j.trans_amt)

    then j.trans_amt

    0 otherwise

    end,

    c_rs = case when j.trans_type_cd = 'C' and sign (jou.trans_amt) = sign (j.trans_amt)

    then j.trans_amt

    0 otherwise

    end,

    v_rs = case when j.trans_type_cd in ('TER', 'FED') and sign (jou.trans_amt) = sign (j.trans_amt)

    then j.trans_amt

    0 otherwise

    end

    Concerning

    Etbin

  • Make a few points on rounded rectangle corner points

    Hello

    I work at the CS6. I would like to cut through a rounded rectangle, so that the result is that one side of computing the corners remain rounded, while the other side they become points of right angle to angle. How can I cut through the rounded without all four sides remaining rounded rectangle?

    Thank you!

    BF,

    I believe you have the effect > esthetics > applied rounded corners.

    Unless you need closed, you can as I suggested in the first post (only ShiftClickDragging with the tool above the sides side line Segment), then uncheck the box and select Direct from the top and press the delete key to leave open at the top.

    Or you can create with the height and the width you want in the first place and just delete the upper side (Direct select it).

    Or you can oppose > decompose the aspect to make it a real rounded Rectangle until you cut.

  • Triangle with rounded corners

    How to draw a triangle with smooth rounded corners and straight walls?

    Hamish,

    You can create the triangle with the tool polygon, delivered with the Rectangle tool (click and place the cursor until the other tools fly away), then the effect > esthetics > corners rounded. You can object > decompose the aspect if you have six anchor points.

Maybe you are looking for