Return-Path: Delivered-To: apmail-jakarta-poi-user-archive@www.apache.org Received: (qmail 72784 invoked from network); 22 Apr 2005 10:04:16 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 22 Apr 2005 10:04:16 -0000 Received: (qmail 13921 invoked by uid 500); 22 Apr 2005 10:04:29 -0000 Delivered-To: apmail-jakarta-poi-user-archive@jakarta.apache.org Received: (qmail 13893 invoked by uid 500); 22 Apr 2005 10:04:28 -0000 Mailing-List: contact poi-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "POI Users List" Reply-To: "POI Users List" Delivered-To: mailing list poi-user@jakarta.apache.org Received: (qmail 13873 invoked by uid 99); 22 Apr 2005 10:04:28 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: local policy) Received: from ngate.noida.hcltech.com (HELO ngate.noida.hcltech.com) (202.54.110.230) by apache.org (qpsmtpd/0.28) with ESMTP; Fri, 22 Apr 2005 03:04:28 -0700 Received: from noida.hcltech.com (exch-01.noida.hcltech.com [204.160.254.79] (may be forged)) by ngate.noida.hcltech.com (8.12.5/8.12.5) with SMTP id j3MA39pu007774 for ; Fri, 22 Apr 2005 15:34:35 +0530 Received: from exch-03.noida.hcltech.com ([204.160.254.29]) by noida.hcltech.com with Microsoft SMTPSVC(6.0.3790.0); Fri, 22 Apr 2005 15:32:49 +0530 Received: by exch-03.noida.hcltech.com with Internet Mail Service (5.5.2653.19) id ; Fri, 22 Apr 2005 15:33:42 +0530 Message-ID: <267988DEACEC5A4D86D5FCD780313FBB07584BBE@exch-03.noida.hcltech.com> From: "Mili Aggarwal, Noida" To: POI Users List Subject: RE: Problem when setting a double value to a cell Date: Fri, 22 Apr 2005 15:33:37 +0530 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: text/plain X-OriginalArrivalTime: 22 Apr 2005 10:02:49.0375 (UTC) FILETIME=[709D62F0:01C54722] X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Hey I faced the same problem. I retrieving a float value from the database which is stored as 32.859 . But In Excel it displays it 32.90 since I had used 2 digit precision but in the formula bar the value was displayed as 32.895000027034. Don't know fro where it is coming from. I system.out.println the value of this float on console. That time it is outputting 32.859. Thus no probs. Seems there is some other prob. Warm Regards, M ---------------------------------------------------------------------------- -----------------------------DISCLAIMER------------------------------------- ---------------------------------------------------------------------------- -------- This message and any attachment contained here are information that is confidential, proprietary to HCL Technologies and its customers. Contents may be privileged or otherwise protected by law. The information is solely intended for the individual or the entity it is addressed to. If you are not the intended recipient of this message, you are not authorized to read, forward, print, retain, copy or disseminate this message or any part of it. If you have received this e-mail in error, please notify the sender immediately by return e-mail and delete it from your computer. -----Original Message----- From: Chamarthy, Ravi Kiran (Exchange) [mailto:rchamarthy@Bear.com] Sent: Thursday, April 21, 2005 10:22 PM To: POI Users List Subject: RE: Problem when setting a double value to a cell Thanks Frans and Amol for your valuable suggestions. Resolved the problem. I changed the code as : int tempvar = (int) (actualdoublevar*100); c.setCellValue((double) tempvar/100); The only problem with this code is if the precision needs to be changed to 3 digits then the code needs to be touched. But anyways the client is very happy. Thanks a lot, Ravi -----Original Message----- From: Amol Deshmukh [mailto:adeshmukh@hobsons-us.com] Sent: Thursday, April 21, 2005 12:36 PM To: 'POI Users List' Subject: RE: Problem when setting a double value to a cell Ravi, Can you post the code that initializes the double variable? My guess is that you are upcasting a float to a double that is the root cause of this loss of precision. In any case, Frans' suggestion is a good one if possible to implement in your scenario. In my excel, i retain the cell values as the formulae which allows users to see the calculations in excel as well as avoids issues like this one. ~ amol > -----Original Message----- > From: Frans.Flippo@INGBank.com [mailto:Frans.Flippo@INGBank.com] > Sent: Thursday, April 21, 2005 11:38 AM > To: poi-user@jakarta.apache.org > Subject: RE: Problem when setting a double value to a cell > > > Hi, > > Well, apparently your variable contains the value 35.590000653. > > You don't say what its type is and how it got its value. If you got it > through some arithmetic operation that uses floats, consider > using doubles. > Or use one of the rounding functions in java.math (round, ceil, or its > relatives). > > Even then, remember that not all numbers can be represented > by doubles. This > inherent to the internal representation used (IEEE 754 > floating point). > Perhaps 35.59 is one of them. This has little to do with either POI or > Excel. > > If you know you want two decimals precision, you might > multiply your number > by 100, round it to an integer, and use a formula in Excel > that divides it > by 100 again, e.g. > > int intvar = variable / 100; > > c.setCellValue("=" + intvar + " / 100"); > > (Or something like that. I've never used formulas from POI, > but I'm sure can > find how to do it in the manual). > > > Good luck, > Frans > > -----Original Message----- > From: Chamarthy, Ravi Kiran (Exchange) [mailto:rchamarthy@Bear.com] > Sent: Thursday, April 21, 2005 5:27 PM > To: POI Users List > Cc: poi-user-info@jakarta.apache.org > Subject: Problem when setting a double value to a cell > > > Hi, > > Can you please help me. > > My code is written as : > > HSSFCellStyle styleDataCommAmt = wb.createCellStyle(); > styleDataCommAmt.setFont(dataFont); > styleDataCommAmt.setAlignment(HSSFCellStyle.ALIGN_RIGHT); > styleDataCommAmt.setDataFormat(format.getFormat("$#,##0.00")); > > c = r.createCell(cellNum++); > c.setCellStyle(styleDataCommAmt); > c.setCellValue(variable);//where variable is of > double type , when > printed shows 35.59 > > > In the generated Excel sheet, the cell shows as 35.59 but > when we click on > the cell the value is in Excel address bar shows as "35.590000653". > > Can you please help me how to solve this. I want the cell > type to be number > only ( else i can do the formatting using NumberFormat Class > and assign the > cell value as string ). > > Any questions please do let me know. > > Thanks, > > Ravi Chamarthy > > > > > > > ----------------------------------------------------------------- > ATTENTION: > The information in this electronic mail message is private and > confidential, and only intended for the addressee. Should you > receive this message by mistake, you are hereby notified that > any disclosure, reproduction, distribution or use of this > message is strictly prohibited. Please inform the sender by > reply transmission and delete the message without copying or > opening it. > > Messages and attachments are scanned for all viruses known. > If this message contains password-protected attachments, the > files have NOT been scanned for viruses by the ING mail domain. > Always scan attachments before opening them. > ----------------------------------------------------------------- > > --------------------------------------------------------------------- To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org Mailing List: http://jakarta.apache.org/site/mail2.html#poi The Apache Jakarta Poi Project: http://jakarta.apache.org/poi/ ********************************************************************** Please be aware that, notwithstanding the fact that the person sending this communication has an address in Bear Stearns' e-mail system, this person is not an employee, agent or representative of Bear Stearns. Accordingly, this person has no power or authority to represent, make any recommendation, solicitation, offer or statements or disclose information on behalf of or in any way bind Bear Stearns or any of its affiliates. ********************************************************************** --------------------------------------------------------------------- To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org Mailing List: http://jakarta.apache.org/site/mail2.html#poi The Apache Jakarta Poi Project: http://jakarta.apache.org/poi/ Disclaimer: This message and any attachment(s) contained here are information that is confidential,proprietary to HCL Technologies and its customers, privileged or otherwise protected by law.The information is solely intended for the individual or the entity it is addressed to. If you are not the intended recipient of this message, you are not authorized to read, forward, print,retain, copy or disseminate this message or any part of it. If you have received this e-mail in error, please notify the sender immediately by return e-mail and delete it from your computer. --------------------------------------------------------------------- To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org Mailing List: http://jakarta.apache.org/site/mail2.html#poi The Apache Jakarta Poi Project: http://jakarta.apache.org/poi/