poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mili Aggarwal, Noida" <mi...@noida.hcltech.com>
Subject RE: Problem when setting a double value to a cell
Date Fri, 22 Apr 2005 10:03:37 GMT
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/


Mime
View raw message