13 Replies Latest reply on Aug 4, 2009 3:40 PM by JosAH

Converting 30 digit number into double,displaying in non-scientific format

Hi All,
I have a String containing value of "1234567891011121314151617181920";(30 digits max in string)
I want to convert this into a number and display it in Excel with the help of POI and i dont want to get those green corener cell warnings.
But after doing Double.parseDouble(), the number is being formatted into xEx format which is undesired in this case.
Any help?
Thanks in advance
Amit
• 1. Re: Converting 30 digit number into double,displaying in non-scientific format
Hi amit.goenka,

Just have a try with the [*BigDecimal*|http://java.sun.com/j2se/1.5.0/docs/api/java/math/BigDecimal.html] API.

Example :
``````BigDecimal bd = new BigDecimal("1234567891011121314151617181920");
double value = bd.doubleValue();``````
• 2. Re: Converting 30 digit number into double,displaying in non-scientific format
Chicon wrote:
Hi amit.goenka,

Just have a try with the [*BigDecimal*|http://java.sun.com/j2se/1.5.0/docs/api/java/math/BigDecimal.html] API.

Example :
``````BigDecimal bd = new BigDecimal("1234567891011121314151617181920");
double value = bd.doubleValue();``````
Think about this Chicon. That is a quart-into-a-pint-pot since double will only hold about 16 significant decimal digits.
• 3. Re: Converting 30 digit number into double,displaying in non-scientific format
sabre150 wrote:
Think about this Chicon. That is a quart-into-a-pint-pot since double will only hold about 16 significant decimal digits.
Hi,

I know that. The OP is using POI : he will have to cut the string in 2 parts and put the results into 2 different cells and then, he will have to merge the cells. Et voilà !
• 4. Re: Converting 30 digit number into double,displaying in non-scientific format
Chicon wrote:
sabre150 wrote:
Think about this Chicon. That is a quart-into-a-pint-pot since double will only hold about 16 significant decimal digits.
Hi,

I know that. The OP is using POI : he will have to cut the string in 2 parts and put the results into 2 different cells and then, he will have to merge the cells. Et voilà !
That is not what you code shows. In fact nothing like it.
• 5. Re: Converting 30 digit number into double,displaying in non-scientific format
sabre150 wrote:
That is not what you code shows. In fact nothing like it.
Indeed, it is why I told him to have a try meaning : Here's an API and look what you can do with it !
• 6. Re: Converting 30 digit number into double,displaying in non-scientific format
Chicon wrote:
sabre150 wrote:
That is not what you code shows. In fact nothing like it.
Indeed, it is why I told him to have a try meaning : Here's an API and look what you can do with it !
That is not the way I read it and I doubt if anyone else will read it that way. Your response implied that one can accurately convert a 30 decimal digit String into a double using using BigDecimal. You can't defend that response and it is not worth you trying.
• 7. Re: Converting 30 digit number into double,displaying in non-scientific format
Ok !
``````BigDecimal bd1 = new BigDecimal("XXXXXXXXXX"); // 15 first digits
double value1 = bd1.doubleValue(); // ---> POI cell 1
BigDecimal bd2 = new BigDecimal("YYYYYYYYYY"); // 15 last digits
double value2 = bd2.doubleValue(); // ---> POI cell 2
// then POI merge cells ``````
• 8. Re: Converting 30 digit number into double,displaying in non-scientific format
Chicon wrote:
// then POI merge cells
And how does that give you a 30-digit double?
• 9. Re: Converting 30 digit number into double,displaying in non-scientific format
jverd wrote:
And how does that give you a 30-digit double?
IMO, it won't give a 30-digit value because even Excell can't treat such value. I'm just hoping the trick won't display the green corner.
• 10. Re: Converting 30 digit number into double,displaying in non-scientific format
Chicon wrote:
jverd wrote:
And how does that give you a 30-digit double?
IMO, it won't give a 30-digit value because even Excell can't treat such value. I'm just hoping the trick won't display the green corner.
When you are up to your neck in a hole that is filling with water - STOP DIGGING.
• 11. Re: Converting 30 digit number into double,displaying in non-scientific format
sabre150 wrote:
When you are up to your neck in a hole that is filling with water - STOP DIGGING.
Don't worry, I can swim !
• 12. Re: Converting 30 digit number into double,displaying in non-scientific format
Chicon wrote:
sabre150 wrote:
When you are up to your neck in a hole that is filling with water - STOP DIGGING.
Don't worry, I can swim !
You're digging a hole in water? Neat trick!
• 13. Re: Converting 30 digit number into double,displaying in non-scientific format
jverd wrote:
Chicon wrote:
sabre150 wrote:
When you are up to your neck in a hole that is filling with water - STOP DIGGING.
Don't worry, I can swim !
You're digging a hole in water? Neat trick!
It can be rocky kind of water ...

kind regards,

Jos ;-)