Noise while formatting double numbers

Hi all,
When I try to format a number with 10 to 12 decimal point, I get noise as the number gets bigger. I know this is because computer can not handle all the floating point numbers when converted to binary. I wanted to see if any one know how to find out how many decimal points I can saw for perticular number with out getting noise at the end. For example, if you try to format double number like 99999.99 using snprintf and try to have 12 decimal points them you get 99999.990000000005. Is there any way to avoid this and work around.
Thanks...

Look up the DecimalFormatter/NumberFormatter APIs.
Steve

Similar Messages

  • 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

  • OAF: Error While Formatting a Read Only MessgeTextInput field of an AdvanceTable "$#,##0.00" format.

    Hi Gurus,
    Please see the below issue I am facing while formatting the field in OAF.
    Situation:
    Custom BidPG page extends a shared region.(sharedRN.xml)
    and in SharedRN I have a advance table, with 5 columns each having  MessageTextInput read only Items.
    While the page is getting loaded values are coming from action fired in the PFR. and getting formatted with a $#,##0.00 format. which I have done over bean of all MessageTextInput items
    using below code in process request.
    Formatter formatter =  new OADecimalValidater("$#,##0.00;($#,##0.00)", "$#,##0.00;($#,##0.00)");
    OAMessageTextInputBean NetincPerMac = (OAMessageTextInputBean)webBean.findIndexedChildRecursive("item243");
    NetincPerMac.setAttributeValue(ON_SUBMIT_VALIDATER_ATTR, formatter);
    Above formatting is working for below cases.
    285 becomes $285.00
    230.45 becomes $230.45
    But in case if there are numbers like 234.254 it will be formatted as $234.254. Here it wont set the precision to 2.
    I want to display till only 2 digits after decimal.
    please let me know Where I am going wrong or missing some steps to do so.
    I have tried below approaches but it did not worked out for me.
              OADecimalValidater dval= new OADecimalValidater("$#,##0.00;($#,##0.00)", "$#,##0.00;($#,##0.00)");
               dval.setMaxPrecision(2);        
              Formatter formatter = dval;
    Also , I have tried to set Currency Code as well to USD but it didnot worked out for me.
    Please let me know how we can set the precision to 2.
    Please note: in process request I dont have data in the bean, I have tried writing a method in controller and setting precision to 2.but it errored out for NULL values coming from bean in process request.
    Please reply. Its an urgent issue needs to be resolved.
    Thanks,
    Premanshu

    On another link I found the following :
    BKI4007E
    File filename cannot be read. Reason: errno(errno number) errno text.
    Explanation:
    Data could not be read due to some system error. Check errno text for further information. If this error recurs, this might indicate some hardware problems.
    User response:
    Contact your system administrator.
    The Link:
    http://ezbackup.cornell.edu/techsup-v5.4/ibmdocs/messages/html/anrcms5878.htm
    Regards,
    Siddhesh

  • Double numbers and precision

    hi, I am trying this:
              double a = 10;
              double k;
              BigDecimal bd = new BigDecimal(a);
              bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
              System.out.println(bd);
              k = bd.doubleValue();
              System.out.println(k);and I get this:
    10.00
    10.0
    which is confusing, because I need to display double numbers with 2 precision digits (DecimalFormat is not usable because it returns Strings)
    I could do that with C, is this possible in Java?

    xpanta wrote:
    hi, I am trying this:
              double a = 10;
              double k;
              BigDecimal bd = new BigDecimal(a);
              bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
              System.out.println(bd);
              k = bd.doubleValue();
              System.out.println(k);and I get this:
    10.00
    10.0
    which is confusing, because I need to display double numbers with 2 precision digits (DecimalFormat is not usable because it returns Strings)
    I could do that with C, is this possible in Java?A double does never have formatting information. (It was a long time ago since I last used C but I can't remember that a double had formatting information there either.)
    Formatting is something you do when you print.
    Kaj

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

  • How to express cell format in Numbers?

    In Numbers on Mac, I want all positive numbers in cells to display in blue with comma separators and a leading + sign.  Example: the value 4135 should appear as +4,135
    I want all negative numbers in cells to display in red with comma separators and a leading - sign.  Example: the value 2167 should appear as -2,167
    I know how to create this in Excel with the custom format [Blue]+#,##0;[Red]-#,##0
    When I create a spreadsheet in Excel, then open the spreadsheet in Numbers, this cell format is not recognized by Numbers.  Does anyone know how to create this cell format in Numbers?  Thx

    Hi pomme4moi,
    You can get the "+", the "-" and the commas in the custom format menu.
    For you colors you need conditional formatting as shown by Wayne.
    quinn

  • How to delete a custom format in Numbers 3

    I am one of the poor unfortunates that has upgraded to Numbers 3 BIG mistake!!
    However does anyone know how to delete a custom format in Numbers 3?
    I'm not sure where the custom format came from in the erlier version of numbers. I guess I must have created it for something, I can't remember what.
    It now appaers that when I send a Numbers 3 document via email to an Excel format  it adds a weird custom format that turns currency into garbage. Once in Excel simply going to format cells and deleting this odd format cures the problem.
    If I could find a way of deleting it in Numbers 3, hopefully the problem will go away.
    This is far from the only problem I'm having with Numbers 3. It's begining to look like I'll have to abandon Numbers 3 having had to go to the expense of buying a new iPad because Numbers 3 documents (and presumably Pages Keynote etc) no longer work on the original iPad.

    I never promote the method the deletion unless you understand the underlying tables of planning, if you search on the forum you will see posts on the subject just like this one - Delete dimension from planning application
    Cheers
    John
    http://john-goodwin.blogspot.com/

  • Error in Number format with numbers 3.0

    Hi.
    I have just purchased Apple Numbers 3.0. It's running on a Mac Book Pro Retina on OS X Mavericks
    I can't use it at all.
    When I enter numbers in the cels it formats the numbers wrong. I'm danish, but run OS X in english with danish region settings.
    What happens is that when i for instance write 20 in B3, it autocorrects it to 0020, and then I can't calculate on it.
    If i set it to English region it works. But since I'm danish I would expect Apple to respect me using my own language.

    Report the bug to Apple with the Numbers > Feedback tool.
    Jerry

  • My printer HP Officejet pro 8600 plus makes a lot of noise while printing

    My HP officejet pro 8600 plus, makes a lot of noise while printing, ink levels are ok, and printing is ok.  it was makiing lines before but not anymore

    Hi,
    Check first if the printer is connected directly to a wall outlet.
    Check if the carriage is moving freely and there is no obstructions inside the unit.
    Clean the paper rollers once.
    See if doing these helps you
    Thanks
    I am an HP employee, these posts are according to my knowledge and HP is not responsible for it.
    Say Thanks by clicking the Kudos Star in the post that helped you.
    Please mark the post that solves your problem as Accepted Solution
    I work for HP.

  • ICloud you have the ability to NOT format phone numbers of contacts; this ability is not available on the contacts of iPhone. If I set-up a phone number in iCloud with NO parenthesis, ex. 123- 456-7899, then this format should be available on the iPhone

    In iCloud you have the ability to NOT format phone numbers of contacts; this ability is not available on the contacts of iPhone. If I set-up a phone number in iCloud with NO parenthesis, ex. 123- 456-7899, then this format should be available on the iPhone contact.

    That is correct is doesn't. Standardized formatting of phone numbers in the iOS app is more important because it supports contact from a variety of locations (gmail, hotmail, etc.). iCloud doesn't (not directly).

  • What keeps making the cyclical noise while in sleep.  Sounds like iMac is loading a graphic or different screen.

    What keeps making the cyclical noise while in sleep?  Sounds like iMac is loading a graphic or different screen.  Does it periodically while in sleep mode.  How do I correct this?  Just started doing it in the last few months.

    I finally figured out how to fix this.  First I reviewed "Mac OS X: Why your Mac might not sleep of stay in sleep mode."  I noted the bullet:  "Do you have any other external USB or Firewire devices connected?"  I have an CP685AVR for a UPS for my Mac.  I replaced the battery a few months ago.  I also hooked up Apple's 'Energy Saver' power management software to the CP685AVR using the USB connection.  I disconnected it, and that solved the problem.  I still have the UPS and battery back-up; I just can't "monitor" the battery.  What's to monitor?  It always said the battery was 100% charged even right up to the time the previous battery failed.  Thanks for listening, uh... reading.

  • Why the currency format in numbers is very limited into few countries???  I think this is a must have in next update of numbers ..

    I was doing a spread sheet for a business proposal to my colleague in Philippines, was very disappointed to know that the currency format in Numbers for Mac is very limited to few countries only...

    As Badunit suggests, in Numbers 2.3 you can turn on the preference that shows the full currency list.
    Put a value in a cell and then choose Philippine Peso.  Save the document.  Open the document in Numbers 3.0 (if that is what you are working with) and you will still have access to that currency.
    You might go to Numbers > Provide Numbers Feedback to let Apple know you need the option to use more currencies in Numbers 3.
    SG

  • Ok so i'm trying to do a conditional format on numbers if (cell a2) = greater than or text then make the same cell or another cell do something. Does anybody knows how to do that on numbers. thanks.

    hi I'm from Italy.
    ok so i'm trying to do a conditional format on numbers if "a cell" = greater than or text then make the same cell
    or another cell do something like insert a number or change color.
    Does anybody knows how to do that on numbers?. thanks.

    Among the things you'll learn from the User Guide:
    Conditional formatting can be used to change the style of the text in a cell and/or the fill colour of the cell.
    A formula may be used to set the value in a cell. In both cases, the format rule or the formula affects only the cell to which the rule is attached or which contains the formula. Neither values or formats may be 'pushed' onto another cell.
    Regards,
    Barry

  • Strange Clicking noise while starting Mac Book Pro Retina Display Late 2013

    Hello i´m very concerned about a clicking noise while starting  my mac, the sound comes from the left side, is the SSD producing  this noise ?, this machines are supposed to be very silent right? what do i do? how can claim a replacement?

    I too think it is related to body chemistry reacting with the metal or some other environmental condition. Sometimes I have fairly sewaty hands and I have corrosion on the edge of my top case. I don't really care about it. Its a tool and tools wear.
    I was told by an engineer that it is referred to as "rusty hands". I'm not sure if its high alkaline or acid, but the engineer told me I had rusty hands after I had been using a drill press for a couple of days. There was rust all over the chuck, and other parts of the drill where I had touched it.

  • BootCamp Assistant Error : Your bootable USB drive could not be created. "An error occurred while formatting the disk."

    I have a Windows 7 Ultimate .iso file saved onto a "Mac OS Extended (Journal)" formatted USB flash drive. I am trying to install it with BootCamp Assistant and I keep getting the error message : Your bootable USB drive could not be created. "An error occurred while formatting the disk."
    I have previously installed Windows 7 on my Mac (and it worked flawlessly - same .iso file), but I uninstalled it because I didn't partition enough space on my hard drive. I have used several flash drive to try and install and none have worked.
    Some help would be greatly appreciated.

    The Boot Camp forum is located here: https://discussions.apple.com/community/windows_software/boot_camp
    The Boot Camp Guides are located here: http://www.apple.com/support/bootcamp/

Maybe you are looking for

  • Webi Stucks while trying to create report with BW7.0 (WIS 10901)

    Hello, I have some problem about using data created from BW 7.0 1. After I try to drag more than one object to create report from webi and run the query, it got sutcked and appear error as below; A database error occured. The database error text is:

  • How can I make a bootable disk so as to repair my drive?

    Hello, I am away from home and not carrying my Tiger install DVD. I had three crashes after installing Safari Beta 2 days ago and now disk utility reports failure on exit when verifying my Macbook drive. To repair this I need to boot from some other

  • Problem opening a certain site properly

    Hello, I have problem opening a certain site properly. I use firefox 4.0.1 and have tried pretty much everything that has already been suggested in other similar problems I found posted here but the site continues to look wrong. No images, blue lette

  • XSD showing many messages while mapping

    Hi experts Can anybody please tell me how to create a single message from one  xsd file(Imported in EXternal Definition) having multiple messages I get the dialog box as : Imported scheme has multiple global elements. Select the global element to be

  • Transferring itunes Account from one computer to another????

    (I tried using the search feature but nothing came up..) Currently I have a laptop that is set up for itunes. What do I need to do to transfer the information from that laptop to another one? Is there any step by step instruction that I can find and