# Thread: Dealing with floating-point in double and String and convert it to String

1. Member
Join Date
Feb 2012
Posts
3
Rep Power
0

## Dealing with floating-point in double and String and convert it to String

My question is a little bit simple but makes me crazy!

Suppose that:

Java Code:
`long number_long = 1100903354159269000;`
I want to show this number as String in output like "1100903354.159269000". To do this, I convert the number to String and perform some basic concatination and it is ok. But I need this new number as Long or Float exactly like this floating point to do some mathematical functions.

How can I do this? The place of floating point is fixed, but the left part of it may increase.
Could you tell me which one is better, Float or Double? How can I convert the result to String with this floating point?

2. Moderator
Join Date
Apr 2009
Posts
13,541
Rep Power
28

## Re: Dealing with floating-point in double and String and convert it to String

If you need accuracy use BigDecimal.
Not sure what you mean by the point being fixed.

3. Member
Join Date
Feb 2012
Posts
62
Rep Power
0

## Re: Dealing with floating-point in double and String and convert it to String

I you need to convert the string to a Float better use the float class constructor as below

String str="111.00001";
Float f = new Float(str);

The string will be converted to a float and you can use for furthur processing.

4. Member
Join Date
Feb 2012
Posts
3
Rep Power
0

## Re: Dealing with floating-point in double and String and convert it to String

Originally Posted by Tolls
If you need accuracy use BigDecimal.
Not sure what you mean by the point being fixed.
WOW! I have not ever seen BigDecimal class! Wonderful and perfect!!
I've done it, it's working, yessssss

Originally Posted by mkarthik90
I you need to convert the string to a Float better use the float class constructor as below

String str="111.00001";
Float f = new Float(str);

The string will be converted to a float and you can use for furthur processing.
Thanks for your reply, but I think the number will become greater than float type variable lenght. BigDecimal meet my needs.