Money Rounding

Hi all,
I've looked-up the BigDecimal class from Math and i wana round the money such that it is always ROUND UP in 5 or 10 cents. Eg:
$100.29 becomes $100.30
$100.22 becomes $100.25
$50.214 becomes $50.25
Any idea how to do this? Thanks

Although using DecimalFormat is a good choice, here is a method that do the rounding (deals with the 123.35000000001 case):
    static final double DELTA = 0.01;
    // num must be positive
    public double round(double num) {
        double numex = num * 100;
        int inumex = (int)numex;
        if ((numex - inumex) > DELTA)
            inumex++;
        int rest = inumex % 5;
        if (rest > 0)
            inumex += 5 - rest;
        return (double)inumex / 100;
    }Regards

Similar Messages

  • Multiply double with const????

    how can I multiply a double with another double, e.g. 1.2345? It does not work, but I can multiply with int. What can I do?

    FWIW, I believe there are some classes out there that allow you to format your output and more importantly in the case of money, round appropriately so that they behave well instead of the infamous truncation that ocurrs that can cause people to lose $$ or deutsche marks, etc.
    -Felix

  • I bought about 4 books at once on amazon for my iPad kindle and then realise that I'm not getting round to reading any of them.  I've gone into two books but two I haven't.  Is there a way of reversing the order and getting my money back?

    Hi I bought too many books at once through amazon for my iPad kindle.  Havent read any of them and Two I haven't actually gone in to, they have a banner across front which says 'new'is there a way of reversing the transaction either with amazon kindle or the iPad kindle application so I cane my money back?

    You should ask Amazon about their returns policy or check the Amazon website. As that's who you bought them from they would be the best people to answer.

  • This does not accept Raw, which I did not know at the time of purchase. I use a DSLR with Magic Lantern firmware so can take Raw vids.  Is there a work round our should I get my money back and find a version that does?

    I have gathered one answer is AE but as I probably only take 6 vids. a year that is too expensive, unless Adobe can organise a pay as you go system that does not cost the earth.

    Timing
    I am not sure what is going on behind the scenes with this web site in the past few days. One day I could not post in your thread at all. Another day
    I was receiving Inbox email notifications that were never posted in the Adobe Premiere Elements Forum or were posted several hours after I saw them
    in my Inbox email notifications. I was waiting for the problem to disappear on its own. If not, we can post in the Adobe Comments Forum to find out what
    might be going on.
    https://forums.adobe.com/community/general/forum_comments
    Yours has not been the only thread where I have had these problems.
    ATR

  • I never put security questions on my apple I'd and now it won't let me buy anything with my money it keeps asking me for the answers that I don't know

    I never put security questions on mt apple I'd and now it won't let me buy anything with my Money I need help A.S.A.P

    Reset Security Questions
    Frequently asked questions about Apple ID
    Manage My Apple ID
    Or you can email iTunes Support at iTunes Store Support.
    If all else fails:
      1. Go to: Apple Express Lane;
      2. Under Product Categories choose iTunes;
      3. Then choose iTunes Store;
      4. Then choose Account Management;
      5. Now choose iTunes Store Security and answer the bullet questions, then click
          Continue;
      6. Sign in with your Apple ID and press Continue;
      7. Under Contact Options fill out the information and advise iTunes that you would
          like your security/challenge questions reset;
      8. Click Send/Continue.
    You should get a response within 24 hours by email.
    In the event you are unsuccessful then contact AppleCare - Contacting Apple for support and service.
    Another user had success doing the following:
    I got some help from an apple assistant on the phone. It is kind of round about way to get in.
    Here is what he said to do and it is working for me...
      a. on the device that is asking you for the security questions go to "settings", > "store" >
          tap the Apple ID and choose view"Apple ID" and sign in.
      b. Tap on payment information and add a credit/debit card of your preference then select
          "done", in the upper right corner
      c. sign out and back into iTunes on the device by going to "settings"> "store" > tap the
          Apple ID and choose "sign-out" > Tap "sign -in" > "use existing Apple ID" and you
          should be asked to verify your security code for the credit /debit card and NOT the
          security questions.
      d. At this time you can remove the card by going back in to edit the payment info and
          selecting "none" as the card type then saving the changes by selecting "done". You
          should now be able to use your iTunes store credit without answering the security
          questions.
    It's working for me ...I just have to put in my 3 digit security pin from the credit card I am using.
    Good Luck friends!

  • HOw do I get my money back from this heap of ****?, HOw do I get my money back from this heap of ****?

    Just subscribed and boy do I want out.
    But the unsubscribe system just goes round in circles.
    The whole thing appears to be a scam
    I just want out and my money back.
    Gerry

    contact adobe support via chat, Contact Customer Care

  • TS4009 How do I get my money back from an iCluod storage plan upgrade that I don't want?

    How do I get my money back from an iCluod storage plan upgrade that I don't want?

    You can cancel an iCloud storage upgrade within 15 days of buying:
    Apple have made this as difficult as possible. However two posters have managed to achieve this. Elizellen was able to use Express Lane to get a refund:
    https://discussions.apple.com/message/19323996#19323996
    However if you use Express Lane may find you cannot proceed without entering a hardware serial number which is still eligible for AppleCare.  julia22 managed to find a way round that by phoning them - please see this post:
    https://discussions.apple.com/message/16968425#16968425
    it gives the USA number - if you don't live there you will have to find an equivalent number from the 'Contact Us' link at bottom right of this page.
    If it is more than 15 days since you purchased the storage you cannot cancel it for a refund; you can downgrade your plan as from your next renewal date. Please see
    http://help.apple.com/icloud/#mmd602084a
    and expand 'Downgrade your storage for the next plan year'.

  • Convert the money datatype to a 2 decimal point format.

    Whats the best way to convert the money datatype to a 2 decimal point format in ms sql 2005 for use in my applications.
    this?
    CAST(tr.depositReceivedAmount AS decimal(10 , 2))

    I respectfully disagree with the notion that you should change the SQL column from a 'money' data-type to something else.
    In most database servers, 'money' is a data type that is designed to provide very consistent behavior with regard to arithmetic accuracy.  In Microsoft Access, the representation is a scaled-integer.  In MS SQL Server, it is obviously similar.  Ditto Oracle and all the others.
    You want the money data-type in the database to have this accuracy, because "hell hath no fury like an accountant in search of one lousy penny."   The database column storage-formats are designed to satisfy accountants, and that is a Good Thing.
    Meanwhile, you also want to take care as to exactly how you deal with the values.  There are several points where rounding could take place.  You do not have at your disposal the strongest possible handling of floating data-types in ColdFusion.  You are also somewhat at the mercy of whatever interface software may lie between you and whatever SQL server you may use.  "It's okay to round values once, but not multiple times."
    I suggest rounding the value right before display, and stipulating that the user's input must be two decimal places.
    Then, you might have to do some things at the SQL server's end.  For instance, when you update a value in the table, you may need to use server-side logic to explicitly truncate the value to two decimal-points, so that an update of "$34.56" explicitly updates the column to "$34.5600."  (This sort of thing has to happen within the SQL server context.)  You know that the user's input has exactly two significant digits, but maybe (maybe not...!) the SQL server might not know this.  You want to ensure that the server's internally-stored value represents exactly two significant digits, when the value originates from a user-input.
    Don't err on the side of "your convenience" or "what looks good on-screen."  (If you do, get ready to get phone-calls from the accountants, always at inopportune hours of the night.)

  • How do i cancel after the circles of hell go round and round?

    I have been in the circles of hell trying to cancel my subscription which my credit card, i was surprised to learn, had been charged for- only to find it is already cancelled! See below
    Adobe ExportPDF, Annual
    Cancelled: Effective February 2, 2016
    Restart
    But I have just been billed for it anyway. And probably be billed for it in another year - 2016. And then it will probably "automatically" (see fine print) restart.and so on till i am very very old. interesting to see on other posts that cancelling the credit card does not help which seems odd but then again after two hours of wandering round and round the site (love the hilarity of the non-functioning chat icon - much hilarity every Christmas in the accounting department.) I'm not surprised. It is clear that adobe has one of the most difficult "unsubscribes" online. Despite the professionals hunting them down and killing them, there are still websites devoted to the topic of why can't I unsubscribe and why is this so hard and surely this is illegal. Adobe clearly makes most of its money out of the unsubscribe because the two products I bought didn't work anyway. Fair enough, should have known, but remind me to employ a lawyer in future before even opening an adobe document.

    Hi there,
    Sorry for the frustrating experience, looking at the account I could see the billing has been stopped for the subscription and you will continue to have the access to software till 2016.
    Please update this thread if you would like to cancel the subscription and get refund.
    ^Ani

  • Rounding up doubles

    Just wondering if anyone knows how to round up a double so that for instance 100.232323 can be up to 100.
    This is due to trying to convert a price in pence to a meaningful price.
    Also is there anyway to represent a figure in pounds and pence???
    Regards.

    If you are working with money you shouldn't do floating point arithmetic. You should either use one of the following:
    1. java.math.BigDecimal. See example: double monthlyInterest = 5.5d / 1200d;
    double monthlyPayment = 700.25d;
    BigDecimal interestAmount = new BigDecimal(monthlyInterest).setScale(5,BigDecimal.ROUND_HALF_UP);
    BigDecimal principalAmount = new BigDecimal(monthlyPayment).setScale(2,BigDecimal.ROUND_HALF_UP);
    BigDecimal appliedPayment = payment.subtract(interestAmount).setScale(2,BigDecimal.ROUND_HALF_UP);
    //to get their double values just do (for example)
    double i = interestAmount.doubleValue();
    double p = principalAmount.doubleValue();
    double payment = appliedPayment.doubleValue();2. Multiply all numbers by a power of 10 (for example 100) and then truncate or round the decimals, then do your arithmetic, then divide by the same number. To truncate, just cast your double value to an int.int newValue = (int) someDoubleValue;To round, you can use any of the java.lang.Math methods.Math.ceil(someDoubleValue);
    Math.floor(someDoubleValue);
    Math.round(someDoubleValue);You can do your own research. :)
    The reason why you should not do floating point arithmetic is because it is not accurate.

  • Rounding up doubles to 2 decimal places

    I'm currently rounding up a double in my program using Math.round(double)
    However I want to strip any trailing zeros from the output, so:
    1.235 would round to 1.24
    but 1.00 would round to 1
    How would I go about doing this?

    Also I'm making my own function to round the doubles,
    and they are returning doubles so I cannot return a
    string.If they are returning doubles that the number of "trailing zeros" is irrelevant, as that is formating. Really you should keep the precision until you want to display it, then use the formatter above.
    What are you doing?
    I'm going to take a shot in the dark; has this got something to do with money?

  • Rounding up currency

    Hi all,
    I am new to java and I was writing my assignment. i hope somebody can help me. I am writing a program which basically calculate what change of dollars you should give to someone. The program works fine when I put figure in integer. but when i put cents in the amount it doesnt work . I know where is the problem. actually I am trying to do this:
    100.10%2
    This returns .099999998 something. I dont know why its not returning .10. I even tried with 2.0 but still the same. Can anyone tell me how I can round it up to .10 or whats wrong here happening.
    Thanx in advance.
    Gurdish Singh

    Regardless of language computers can only distinguish between a finite number of different floating point values. And as a result floating point types, as commonly implemented, only have a certain amount of precision. This makes them a different sort of beast from the mathematician's (infinitly precise) numbers. Both the mathematician and the computer attempt to model actual real world quantities, but they do so in subtly different ways.
    En wrote:
    Others will likely post you links that you should read to better understand this.Here's a couple:
    * David Golberg's [What Every Computer Scientist Should Know About Floating-Point Arithmetic|http://docs.sun.com/source/806-3568/ncg_goldberg.html]
    * An old Bill Venners [JavaWorld article|http://www.javaworld.com/javaworld/jw-10-1996/jw-10-hood.html]
    En wrote:
    For most this is more a problem of display rather than accuracy.I think that is the case here.
    OP wrote:
    actually I am trying to do this:
    100.10%2Are you happy with the % operator? It returns the remainder after dividing 100.10 as many times as possible by 2.
    OP wrote:
    This returns .099999998 something.What it really returns is "the remainder after dividing 100.10 as many times as possible by 2". (As accurately as inherently imprecise fp numbers can.)
    If you want to want to do further arithmetic with this number the best thing to do is ... nothing at all. It is already as accurate as it's ever going to get. And any rounding or other fiddling about with its value can only make it less accurate.
    If you want to display this value to a user, they won't appreciate seeing a string like ".099999998". So we format the string they see. From the mathematician's point of view "the remainder after dividing 100.10 as many times as possible by 2" represents one number and ".099999998" represents another. So some rounding will have taken place. But from the computer's point of view it's not rounding, but formatting: displaying a given fp number in a way the user will find palatable.
    (And if you want to do both, you can. Format the number for the user, but retain its value unchanged for further arithmetical work.)
    [String.format()|http://java.sun.com/javase/6/docs/api/java/lang/String.html#format(java.lang.String, java.lang.Object...)] is a very easy way to do this. Or its cousin, the PrintStream (etc) method [printf()|http://java.sun.com/javase/6/docs/api/java/io/PrintStream.html#printf(java.lang.String, java.lang.Object...)]. At some point you will have to have a look at the Formatter documentation for details: especially the secions on "Format string syntax" and "Conversions".
    Edited by: pbrockway2 on Aug 18, 2008 12:00 PM
    I've just read that it's a money problem...
    One way to sidestep the imprecise->inaccurate problem is not to use floating point types. If you store and manipulate the money values as cents (pennies etc) you could do so with int (or long). The finite nature of computers shows up here in the the finite range of these types, but not with imprecision. 10010 cents is quite precise: it's not 10009 nor 10011. And 10010%2 will give just the value you expect. (Some formatting still required though since you will have to put a dot in the displayed string.)

  • Money/Currency primitive

    Could a 'money' or 'currency' primitive be added to the Java language specification? Something with 2 decimals places and proper rounding logic?
    Anyone who has ever coded with BigDecimal or longs knows what I'm talking about. It's a major pain in the *ss and not doing the work leads to the stealthy rounding-error.
    Operator overloading would work - since I could code my own class but I've found operator overloading to usually cause more unreadable code than it's worth.
    I don't think name collision would be a problem since class names are defacto propercase.
    What do you guys think?
    Jason.

    way back while programming adventuregame I did a class which would calculate expressions... the variables were in hashtable and the class could be submitted with something like this "(characterposx+manposx)/2"... maybe you should create this kind of class... first you submit variables
    definevar("aVar", 130*100+13); // should currency be defined as long with decimals being the %100 part?
    calculate("aVar*aVar-aVar+100"); // sure this will take time to parse the expression
    // and so on, but could be more easy and more
    // adjustable. Maybe you could precompile it to an array of
    // integers that represent bytecode kind of interface for
    // this fast financical expression calculator...I think that this went well beyond the topic, but consider it. Might not be all bad. Might be worth effort even.

  • BigDecimal: how to  keep 2 fraction digits, round up.

    Hi,
    To calculate money amount, we need to have 2 fraction digits.
    For example,
    8888.567 --> 8888.57
    99998888.865 ---> 99998888.87
    0.982 --> 0.98
    for method round(MathContext), the mathContext specifies total number of digits, not fraction digits.
    The workaround we have to use:
    amount.divide(new BigDecimal("1"), 2, RoundingMode.HALF_UP);
    what is the right way to achieve 2 fraction digits/half-UP?
    Thanks for help.
    Dave

    When handling money you are better off not using decimals. You can either create your own Money class which has 2 variables: dollars and cents. Or use ints for all calculations and then simply divide by 100 when you want to display. So one dollar fifty is int of 150 and not double of 1.5.

  • Clear table for new round in Poker?

    Currently, I have some code like this in a Texas hold 'em poker
    public TableGUI(Player humanPlayer, PlayerNovice comPlayer, double minBet) {
    //Display table
    public void actionPerformed(ActionEvent event) {
    //"Deal" cards button to start new round
    //Once cards are dealt, disable Deal button.
    //Player take turns, table deals other cards
    //Show down
    //Result is compared, find winner, update each player's money
    public static void main(String[] args) {
             //Schedule a job for the event-dispatching thread:
            //creating and showing this application's GUI.
          javax.swing.SwingUtilities.invokeLater(new Runnable() {
              public void run() {
                 createAndShowGUI();
       private static void createAndShowGUI() {
            //Make sure we have nice window decorations.
            JFrame.setDefaultLookAndFeelDecorated(true);
            Player tmp1 = new Player("GurLuver", 50.0);
            PlayerNovice tmp2 = new PlayerNovice("Master Computer", 50.0);
            double minBet = 1.0;
             TableGUI frame = new TableGUI(tmp1, tmp2, minBet);
    However, after that (winner found, update money), I need to let the player start a new round, which means:
    - All the cards on table are removed (Each of the card is actually a JPanel.
    - Money of each players is bring to next round
    Can somebody tell me how to do the 2 tasks above? Thanks

    ... is it so...
    Well, let me try to rephrase my questions then...
    How do you remove some JPanel while re-newing other object in it?
    Say if you have a frame which contains JPanel , an Object and some integer. How do you remove the JPanel, create a new instance of Object while keeping the integer value?

Maybe you are looking for

  • SOAP: "XI.Timeout" module in the sender adapter

    Hi,       Could you please explain in detail, how to enter the XI.timeout module in the soap sender adapter. Regards, Vishnu.

  • Streaming audio (radio stations)

    Is it possible to access streaming audio via radio staion web sites on my Curve?

  • Open in an old version

    My graphics guy used InDesign CS3 to create a brochure for me. I have InDesign 2.0 on my computer. Is there a way he can export it so that I can edit it on my computer. I've been unable to open either the .inx or the .indd files that he has sent me.

  • When I upgrade will I lose my stuff?

    I have the Snow Lepord OS system and I want to upgrade to Mountain Lion. I was wondering if anyone else has done this and if they lost their stuff? What I mean by stuff is like pictures, music, files, etc.. Thanks! Alyssa

  • OBIEE / BI Publisher report question

    Hi, quick OBIEE / BI Publisher question. We have a requirement to produce a very formatted, complex report. All of the data exists in OBIEE - but there are multiple subject areas needed to answer the questions (thus multiple Answers queries). Assumin