Re: Convertion from String to Float
- From: CD1 <cristiandeives@xxxxxxxxx>
- Date: Tue, 24 Jul 2007 18:10:37 -0000
Hi Pedro,
As Daniel pointed out, you should use the NumberFormat/DecimalFormat
classes. Here's an example:
NumberFormat formatter = NumberFormat.getInstance();
float f = formatter.parse("1,685");
The getInstance method creates an instance of NumberFormat in the
current locale (my locale is Brazilian Portuguese, which uses comma to
separate decimal values, and that's why it worked). You can pass a
Locale object to specify a non-default locale.
If you need a more accurate formatting, try the DecimalFormat class.
You can construct an object of this class with a custom format.
See ya!
On Jul 24, 11:52 am, Pedro Pinto <kubi...@xxxxxxxxx> wrote:
Thank you for the replies. The solution adopted was:
temp = value.split(",");
value = temp[0]+"."+temp[1];
numero = Float.parseFloat(value);
I'll use the replace later to avoid all these operations.
Thanks once again
Regards
Pedro Pinto
.
- References:
- Convertion from String to Float
- From: Pedro Pinto
- Re: Convertion from String to Float
- From: Daniel Pitts
- Re: Convertion from String to Float
- From: Pedro Pinto
- Convertion from String to Float
- Prev by Date: Re: java class hierarchy
- Next by Date: Re: Moving an image
- Previous by thread: Re: Convertion from String to Float
- Next by thread: Re: Convertion from String to Float
- Index(es):
Relevant Pages
|