Adding two special double numbers

Adding two double numbers.
say, 12543.34 and 42895.00 am getting in the decimal part .3999999.
Now I want .34 instead .399999 and how??
Can any body help me ??

Read this (or search the forums--this question is asked at least once a day):
http://docs.sun.com/source/806-3568/ncg_goldberg.html

Similar Messages

  • Adding two random generated numbers together?

    I'm writing a program for a class in which we have to simulate a two die rolling. So I got the computer to generate to random numbers, and now I need to add them to get the rolled die's sum. This info will then be organized into a chart. But I have no idea how to add to randomly generted numbers together, can anybody help me??
    import java.util.Random;
    import java.util.Scanner;
    public class Test
        public static void main(String [] args)
            //Start
            Scanner in = new Scanner (System.in);
            int randDieNum1 = 0;
            int randDieNum2 = 0;
            Random randDieNum1List = new Random();
            Random randDieNum2List = new Random();
            //User Input
            System.out.print("Number of Rolls: ");
            int numToRoll = in.nextInt();
            //Testints
            //Loop
            for(int rolled = 0; rolled != numToRoll; rolled ++)
                int randDie1 = randDieNum1List.nextInt(6) + 1;
                int randDie2 = randDieNum2List.nextInt(6) + 1;
                System.out.println("RandNum1: " + randDie1);
                System.out.println("RandNum2: " + randDie2);
                int final = (int)randDie1 + (int)randDie2;
                System.out.println("Add: " + randDie1 + randDie2);
    }

    You can't call the variable "final" as that's a Java keyword. Try something like "sum" or "total".
    (Also consider just using a single Random object and calling it twice to obtain the value for each of the dice.. And don't (cast) for the fun of it or as a talisman to ward off compiler messages.)

  • Adding two double numbers is a problem

    Hi friends..
    when we try to add the two double numbers say,
    119.52, 10.00
    here we should get 129.52
    but it is giving as 129.51999999999998
    Here i want to round this to two digits after decimal point
    if i round the above value i will get 129.52 and the problem will be solved.
    But we don't know exactly on what basis we are getting the sum as 129.51999999999998.
    Assume that, tomorrow when we are adding some other numbers we may got like
    129.51444444444448
    when we round this we get 129.51
    but actually we have to get 129.52.
    If anyone know why the system is giving that wrong sum amount, please give solution to avoid this.
    To solve this problem, i tried by converting the double numbers to integers and adding these integers and finally converting the sum into double...like
    if
    d1= 119.52
    d2=10
    int x = (int)(119.52*100.00);
    int y = (int)(10.00*100.00);
    int z = x + y;
    double d = (double)(z)/100;
    This is working for this case...
    But when we are applying this approch to other numbers it is giving problem....
    i.e, if i convert like below
    int x = (int)(72.46*100.00);
    this should give x=7246
    but it is giving x=7245
    What is the solution for this problem...please give immediate reply.....

    Assume that, tomorrow when we are adding some other
    numbers we may got like129.51444444444448
    That isn't going to happen. The numerical computations are deterministic. The problem lies in your understanding of how numbers work.
    This has been repeated before so if you want more detail I suggest you search the forums for discussion on precision and double.
    Computers store numbers in binary. The number you are trying to represent is a decimal number. This produces an error in precision.
    The same problem exists in decimal notation. Decimal notation can not accurately represent one divided by three (in decimal 0.33333333.....).

  • Problme while adding double numbers.

    Hi,
    I am trying to get a series of double numbers by adding some constant value to a double number.
    so when i try to add .01 to 10.04 i am getting the result as 10.0499999.. instead of 10.05
    is there any work around for this problem.
    Thanks

    Can Someone tell me please what is going on?
    Trying to add simple double numbers but the result is really surprising.
    double postage = 0.72 ;
    double total = 0.18;
    double totalamt = postage + total;
    System.out.println(totalamt);
    Result: 0.8999999999999999 INSTEAD OF 0.9

  • Problem with the  addition of  double numbers

    when we try to add the two double numbers say,
    119.52, 10.00
    here we should get 129.52
    but it is giving as 129.51999999999998
    This is happening only for sum numbers.
    Here i want to round this to two digits after decimal point
    if i round the above value i will get 129.52 and the problem will be solved.
    But we don't know exactly on what basis we are getting the sum as 129.51999999999998.
    Assume that, tomorrow when we are adding some other numbers we may got like
    129.51444444444448
    when we round this we get 129.51
    but actually we have to get 129.52.
    If anyone know why the system is giving that wrong sum , please give solution to avoid this.
    In My application , i want the exact sum amount so if i add some numbers i should get exact sum.
    like 119.52+10=129.52
    i want exactly this. How to get this.

    As another poster said, this is a topic worth reading up on, as there are subtleties involved in this kind of imprecise math. A couple of points to get you started though...
    * Java's double type has a precision of something like 16 (20? 24?) decimal places. (You should be able to find the correct number in the lang. spec., or someone may be kind enough to post it here.) I don't remember the formal definition, but what this means, approximately, is that any number that can be represented will be accurate to within +/-0.5*10^-16 of its value. That is, if the actual value is 2e5, then the absolute value of the error in the representation will be less than 0.5e-11. (I might be off be a factor of 2 and/or an order of magnitude here, but you get the general idea.) The good news is, no value will be in error by more than that amount. The bad news is, any value could be in error by up to that amount. These are the two key points.
    * Compare the precision implicit in your data and needed in your results to that of Java, along with the number of intermediate calculations you'll do to get a final result. For instance, if you're doing financial calcs in the tens of billions of dollars, and you need accuracy to the penny, that's one part in 10^-12. Assuming any given value is off by no more than one part in 10^-16, and assuming all errors are in the same direction, if you do 10^4 cumulative additions, you'll be off by a penny. Again, these are rough, and I may have missed something, but this is the kind of thing to look at to determine how the inherent imprecision will affect you.
    * Don't round any intermediate results. Keep the precision you have. However, when you're comparing (as jschell demonstrated) make a copy of the value and round that copy before doing the comparison. Use the first two points above to determine whether that rounding will meet your needs for precision. Same goes for displaying.
    * Finally, if the 10^-16 (or whatever it was) precision of a double is not sufficient, you can get arbitrary precision with BigDecimal. There are a couple of caveats, however. 1) It's a lot slower than using primitives ans 2) Arbitrary precision does not mean infinite precision. You can specify as many decimal places as you want (subject to time and memory constraints), but you even if you specify 1,000 decimal places, you can still be off by 5 in the 1001st place.

  • Two different page numbers on the same page

    Hi guys, I have this problem, in my documents I have a main numbering like this <$chapnum>-<$curpagenum> and a second composing a lot of file-cards, in this file there's a double numbering, the main flow global numbering, and the local numbering <$cupagenum>/<$lastpagenum>.
    I don't know how differentiate this numbering, I would like in the same pages something like : 1-329, 1-330, 1-331 and 1/4, 2/4, 3/4, 4/4.
    thank you!

    Ok thank you, I try. I have a techincal manual of 400 pages,
    at the end I have a Appendix with 100 technical file-cards,
    so the numbering is: from page 1 to 400 for the entire manual,
    from 300 to 400 for the file-cards.
    Every file-card is composed by about 10 pages
    and have its own numbering, each page is numbered
    like (1 of 10, 2 of 10 , CurrentPageOfThisCard of TotalPageOfThisCard)
    and this numbering is in a little text frame on the page.
    The first file-card is inserted after the page 299,
    the second file-card start at page 310, the third at 320, etc..
    So, for example, looking the second file-card, the first page of the card
    Is at page 310 of the manual, the second page at 311 and so on.
    The relation is only the position of the file-card in the manual.
    I need to autonumber these two levels of pages.

  • Boolean double is in range of two other doubles.

    First, I apologize if this is in wrong forum, seems I can never decide which forum I should ask my questions in and I get jumped on, so if this is wrong I am sorry.
    I have been searching every where for a boolean range checker to tell me if a user input (double) is in between two double numbers. Where can I find something on how to do this? Searches I have done have turned up nothing. I do not want someone to do it for me, I want to learn.
    Thank you
    javahelp44

    javahelp44 wrote:
    I tried doing something like that putting an if statement in my try block, but I kept getting an illegal expression start error I think it was. So I was under the impression I could not use an if staement inside the try block. I will try again...The error message contains actual useful information. It's there to help you. It's not the compiler biting at your fingers -- you don't have to jump back and remove the new code in a panic. Read the error message, consider what it says, try to understand it, adjust your code accordingly. If you really don't understand an error message, then post it here (the full thing not just some paraphrase) and the relevant code and ask for help.

  • How to add two different page numbers in a single page

    How to add two different page numbers in a single page? One is for page number of the whole article, the other one is for page number for each chapter in the article.

    It's quite complicated, see
    Two Page Numbering Schemes in the Same Document.
    Regards, Hans Vogelaar (http://www.eileenslounge.com)

  • I have two different 5s's with two different phone numbers but they are both using the same iCloud/apple account. After upgrading to iOS8 when I get a phone call on one phone both phones ring.

    I have two different 5s's with two different phone numbers but they are both using the same iCloud/apple account. After upgrading to iOS8 when I get a phone call on one phone both phones ring. One phone is for work and one is for private and I don't need both phones to ring from one call. It's bizarre.......is this supposed to be like this? If so where can I turn it off?? And while we are at it iOS8 has installed iBooks on both of my phones and iTunes won't let me uninstall it. I don't need or want iBooks on my phones.

    Hi,
    There are two easy fixes to this.
    One, you can set up Family Sharing, in which you can have two different iCloud Accounts, yet still share the same apps, music, media etc.
    Two, go to Settings and turn-off "Handoff". This can be found under the General page.
    Hope this helps!

  • I accidentally added two .doc files, they show in iTunes file sharing, but don't show on iPad?

    I accidentally added two .doc files by dragging and dropping into itunes, under my device, then the app tab, then file sharing for Adobe Reader, they show in iTunes file sharing window, but don't show on iPad 3, and I cannot delete them on iTunes screen? Please help!

    First, I would advise you to apply Tao philosophy to this. Given the dysfunction of most software, if this was just an accidental copy and you don't want them on iPad and they are not showing up anyway, what's the problem? Forget it. It's not worth the hassles. I'm more concerned that you have psychological issues you need to be dealing with, not this. You are making much too unnecessary work and stress for yourself.
    As for deleting them, I'm assuming you highlighted them and hit delete and it didn't work. If not, it should. Works for me. But if it doesn't, my advice is also not to worry about it, as annoying as the clutter is. It will eventually resolve itself (like when your data files corrupt or your iPad crashes, LOL. (I apologize for my cynicism but I am fed up with dysfunctional software). It's not worth the hassles of trying to figure out petty issues.
    As for me, I have the opposite, and very serious problem. I've got Reader on my iPad too. But I can't move the pdfs out of it and onto my laptop with iTunes' dysfunctional file sharing. I get the error "file cannot be copied because you do not have permission to see its contents." I have hundreds of pdfs on my iPad that I converted from web surfing with other programs that also don't work and I can't get them off the iPad for backup and to have a synced library I can access from both laptop and iPad.
    I called iTunes twice and both times they blamed it on the app, saying iTunes file sharing doesn't support third party apps and that I should call Adobe and talk them into writing the code that will work with iTunes. Yeah, right. And Reader is not the only problem. This is happening with iAnnotate and Write PDF and other apps.
    I suspect that both of us have the root problem, perhaps Apple's greedy refusal to support the apps that it sells in the app store and are quasi-integrated enough to show up in the file sharing documents list, but can't be moved or deleted; and the apps that don't bother to make their apps fully work with iTunes file sharing.
    If anyone has any solutions ......

  • I'm tring to install two Daqcard700​'s in same computer running Win2000 and Nidaq6.9.2 and the cards are not given two different device numbers by the NIDAQ device configurat​ion wizard.

    One Daqcard 700 and one daqcard 16x-50e in same machine work fine but two Daqcard 700's are not assigned two diferrent device numbers by the device configuration wizard.

    I have this same problem with the previously described observations.  I tried two Daqcard-700s in three different laptops, two with Windows XP and One with Windows 2000.  Tried all suggestions in Knowledgebase and Forum I could find with no luck.  Single cards work ok.  Removed and reinstalled drivers in Device Manager.  Tried the Windows 2000 patch for this problem.  Changed the PCMCIA adapters on the laptop to Generic Cardbus  Controller from one suggestion.  Running Labview 6.1 with Ni-Daq 6.9.3 and Max 3.1. Tried also Max 2.1.
    Any help will be greatly appreciated.
    thanks,
    Ben1167

  • Problem araised in  adding two custom fields to ksb1 tcode.

    hi experts,
      I added tow fields vendor no, vendor name to Tcode:KSB1.
    i used user-exit :   coomep01 .
    in this exit i added two fields to ci_rkpos (include table) . i.e zlifnr,zname1.
    but that problem is ci_rkpos is not appearing in green color it means it is not transported .
    in development  client is working properly .
    using sm34 i added fields names.
    error is coming like this.
    The following syntax error occurred in the program SAPLXKAEP :
    "The data object "CS_RECORD" has no component called "ZLIFNR", but ther"
    Error in ABAP application program.
    The current ABAP program "SAPLKAEP" had to be terminated because one of the
    here wat ever we add the zfields will appear in kaep_coac ,so in this structure two added fields are appeared in dev client
    but,the same zfields when transported to quality is not appearing .
    please suggest how to do??

    hi breakpoint.
    yes i attached  in transport.
    in quality client.
    wat ever i wriiten code  in user exit it is coming ,but
    incldue table structure is not coming ,and even that fields are appearing in v_tkalv ,but in structure kaep_coac
    blank include strcuture CI_RKPOS is appearing ,but
    in dev client is working properly, and in quality first of all report is going to dump.
    here this tvode is using all 3 plants,how can i restrict to specified plant so that ,it will not affect others plant.
    suggest me how to do??
    Edited by: kamalsac on Aug 18, 2010 10:57 AM

  • Adding two leading zeroes infront of a variable(both character and numeric)

    Hi Experts,
    I have a variable v_data. Whatever is the value of the v_data, two leading zeroes should get added to it.
    v_data may be numeric or charachter type.
    I am using FM CONVERSION_EXIT_ALPHA_INPUT for adding two preceding zeroes for numeric types but for character types what logic I should use?
    Currently I am doing:
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input         = v_data
    IMPORTING
       OUTPUT        = v_data.
    if v_data CA 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.
        SHIFT v_data BY 2 PLACES right.
        v_data+0(1) = '0'.
        v_data+0(2) = '0'.
    endif.
    But the above code is giving output like this: 0 P0001 but I want output like 00P0001.
    How to fix it?
    Regards,
    Sangeeta.
    Edited by: Sangeeta on Nov 11, 2008 6:22 AM

    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
    EXPORTING
    input = v_data
    IMPORTING
    OUTPUT = v_data.
    if v_data CA 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.
    SHIFT v_data BY 2 PLACES right.
    v_data+0(1) = '0'.
    v_data+1(1) = '0'.   " change this
    endif.

  • I have added two new extension on CUCM, Directory not showing in attendant console even after resynch on CUCM and attendant cosn

    I have added two new extension on CUCM, Directory not showing in attendant console even after resynch on CUCM and attendant cosnole
    Any idea?

    Hello,
    Can you tell us what versions of CUCM and CUxAC you are using?  Just extensions alone in CUCM will not sync to the corporate directory within the attendant console application.  You will at least have to have user's associated with those extensions and depending on your rule set within the console that should then bring those extensions into the console directory.
    Thanks,
    Tony

  • Can I get iMessages from two separate phone numbers

    I have two iPhones with two separate phone numbers and two separate Apple ID's.  I would like to get the messages being sent to my computer to come in from both phone numbers.  Is this possible?

    Hi,
    for the   Points
    Thank you.  Now....can you explain to me HOW to do this?
    I was sorely tempted to say "yes" again.  (I can explain) 
    8:28 pm      Thursday; April 9, 2015
    ​  iMac 2.5Ghz i5 2011 (Mavericks 10.9)
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro 2Gb (Snow Leopard 10.6.8)
     Mac OS X (10.6.8),
     Couple of iPhones and an iPad

Maybe you are looking for

  • Error while calling a webservice from ABAP system

    Hi All, I have generated a proxy for the webservice that is there in a Java system. Iam getting the following error when I make a method call of that generated proxy. SOAP:1.026 SRT: HTTP-Code 500: ("Internal Server Error"). Does anybody has any idea

  • When I go into app store on iPod touch and click on an app i get can't connect to iTunes

    I noticed it on jan 1 but was working fine on dec28 when I bought it. All I have done is download apps I had previously purchased on my old 3G iPod 32gb touch To my 5g 32gb iPod touch using purchases on the update part of app store. Please help me do

  • Badi for updating Item Gross Weight  (VL01N)

    Hi All I am using interface CHANGE_DELIVERY_ITEM and FILL_DELIVERY_ITEM of defination name LE_SHP_DELIVERY_PROC to change the gross weight of delivery item.  System is allowing me to change the gross weight in interface CHANGE_DELIVERY_ITEM but is no

  • Disable Filevault on Yosemite?

    Hey, I just updated to Yosemite and in the set-up window I activated Filevault having a different idea about it. However, when I went to disable, it won't let me until it's all encrypted. Will I have to wait until it's all encrypted to disable it? Or

  • "Access Denied" System Error When Installing Software

    I reintalled the Mac OS 10.4.6 and preserved my users data. Now every time I try to install program, I get the following message: Sorry, the operation could not be completed due to a system error: (Access Denied). I tryed repairing the permissions. A