Re: [java ee programming] ParseDouble problem

2011-07-17 Thread wescley costa
Rafael,

   The John's solution it´s better than mine.

regards

Wescley

2011/7/16 Rafał Laczek 

> Hi,
>
> Thanks for advice.
>
> Finally I sued
>
>  double val = Double.parseDouble(strValue.replace(oldChar, newChar));
>
> In my case it was:
>
>
> *double* resultDoub = Double.*parseDouble*(resultStr.replace(",", "."
>
> ));
>
> Regards,
>
> Rafal
>
>
>
> Dnia 16-07-2011 o godz. 18:09 John Masseria napisał(a):
>
> Take a look at NumberFormat:
>
>
> http://download.oracle.com/javase/1,5.0/docs/api/java/text/NumberFormat.html
>
>
>  public abstract class *NumberFormat*
> extends Format 
> 
>
>  NumberFormat is the abstract base class for all number formats. This
> class provides the interface for formatting and parsing numbers.Â
> NumberFormat also provides methods for determining which locales have
> number formats, and what their names are.
>
> NumberFormat helps you to format and parse numbers for any locale. Your
> code can be completely independent of the locale conventions for decimal
> points, thousands-separators, or even the particular decimal digits used, or
> whether the number format is even decimal.
>
> To format a number for the current Locale, use one of the factory class
> methods:
>
>   myString = NumberFormat.getInstance().format(myNumber);
>
>
>  If you are formatting multiple numbers, it is more efficient to get the
> format and use it multiple times so that the system doesn't have to fetch
> the information about the local language and country conventions multiple
> times.
>
>  NumberFormat nf = NumberFormat.getInstance();
>  for (int i = 0; i < a.length; ++i) {
>  output.println(nf.format(myNumber[i]) + "; ");
>  }
>
>
>  To format a number for a different Locale, specify it in the call toÂ
> getInstance.
>
>  NumberFormat nf = NumberFormat.getInstance(Locale.FRENCH);
>
>
>  You can also use a NumberFormat to parse numbers:
>
>  myNumber = nf.parse(myString);
>
>
> 2011/7/16 Rafał Laczek 
>
>> Hi Colleagues,
>>
>> In my application I have input string field.
>> String resultStr is parsed into double.
>> The problem is when resultStr is with "comma" eg. 2,3 instead of 2.3 (with
>> dot).
>> Can I solve it in any way?
>> Bellow is my current code.
>> double resultDoub =Double.parseDouble(resultStr);
>>
>> Thanks in advance for advice.
>>
>> Regards,
>> Rafal
>>
>>
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Java EE (J2EE) Programming with Passion!" group.
>> To post to this group, send email to
>> java-ee-j2ee-programming-with-passion@googlegroups.com
>> To unsubscribe from this group, send email to
>> java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com
>> For more options, visit this group at
>>
>> http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en
>
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Java EE (J2EE) Programming with Passion!" group.
> To post to this group, send email to
> java-ee-j2ee-programming-with-passion@googlegroups.com
> To unsubscribe from this group, send email to
> java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com
> For more options, visit this group at
>
> http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en
>
>
>
>  --
> You received this message because you are subscribed to the Google
> Groups "Java EE (J2EE) Programming with Passion!" group.
> To post to this group, send email to
> java-ee-j2ee-programming-with-passion@googlegroups.com
> To unsubscribe from this group, send email to
> java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com
> For more options, visit this group at
>
> http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en
>

-- 
You received this message because you are subscribed to the Google
Groups "Java EE (J2EE) Programming with Passion!" group.
To post to this group, send email to
java-ee-j2ee-programming-with-passion@googlegroups.com
To unsubscribe from this group, send email to
java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en

Re: [java ee programming] ParseDouble problem

2011-07-17 Thread wescley costa
hello,

If you used jdk 1.5+, you will can try the String method replace (link
below), this way, all comma separator in the number will be change in dot
separators. Take care with numbers that contains dot separtor as decimal
before execute this one.

http://download.oracle.com/javase/6/docs/api/java/lang/String.html#replace%28java.lang.CharSequence,%20java.lang.CharSequence%29

regards,

Wescley



2011/7/16 Rafał Laczek 

> Hi Colleagues,
>
> In my application I have input string field.
> String resultStr is parsed into double.
> The problem is when resultStr is with "comma" eg. 2,3 instead of 2.3 (with
> dot).
> Can I solve it in any way?
> Bellow is my current code.
> double resultDoub =Double.parseDouble(resultStr);
>
> Thanks in advance for advice.
>
> Regards,
> Rafal
>
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Java EE (J2EE) Programming with Passion!" group.
> To post to this group, send email to
> java-ee-j2ee-programming-with-passion@googlegroups.com
> To unsubscribe from this group, send email to
> java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com
> For more options, visit this group at
>
> http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Java EE (J2EE) Programming with Passion!" group.
To post to this group, send email to
java-ee-j2ee-programming-with-passion@googlegroups.com
To unsubscribe from this group, send email to
java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en

Re: [java ee programming] ParseDouble problem

2011-07-16 Thread Rafał Laczek

Hi,

Thanks for advice. 
Finally I sued 


double val = Double.parseDouble(strValue.replace(oldChar, newChar));
In my case it was:



 
double resultDoub = Double.parseDouble(resultStr.replace(",", "."
));

Regards,
Rafal
 

Dnia 16-07-2011 o godz. 18:09 John Masseria napisał(a):
Take a look at NumberFormat:

http://download.oracle.com/javase/1,5.0/docs/api/java/text/NumberFormat.html



public abstract class NumberFormat
extends Format

NumberFormat is the abstract base class for all number formats. This class provides the interface for formatting and parsing numbers. NumberFormat also provides methods for determining which locales have number formats, and what their names are.
NumberFormat helps you to format and parse numbers for any locale. Your code can be completely independent of the locale conventions for decimal points, thousands-separators, or even the particular decimal digits used, or whether the number format is even decimal.
To format a number for the current Locale, use one of the factory class methods:

  myString = NumberFormat.getInstance().format(myNumber);
 

If you are formatting multiple numbers, it is more efficient to get the format and use it multiple times so that the system doesn't have to fetch the information about the local language and country conventions multiple times.

 NumberFormat nf = NumberFormat.getInstance();
 for (int i = 0; i < a.length; ++i) {
 output.println(nf.format(myNumber[i]) + "; ");
 }
 

To format a number for a different Locale, specify it in the call to getInstance.

 NumberFormat nf = NumberFormat.getInstance(Locale.FRENCH);
 

You can also use a NumberFormat to parse numbers:

 myNumber = nf.parse(myString);


2011/7/16 Rafał Laczek 
Hi Colleagues,In my application I have input string field.String resultStr is parsed into double.The problem is when resultStr is with "comma" eg. 2,3 instead of 2.3 (with dot).Can I solve it in any way?Bellow is my current code.double resultDoub =Double.parseDouble(resultStr);Thanks in advance for advice.Regards,Rafal--You received this message because you are subscribed to the GoogleGroups "Java EE (J2EE) Programming with Passion!" group.To post to this group, send email tojava-ee-j2ee-programming-with-passion@googlegroups.comTo unsubscribe from this group, send email tojava-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.comFor more options, visit this group athttp://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en


 
-- You received this message because you are subscribed to the GoogleGroups "Java EE (J2EE) Programming with Passion!" group.To post to this group, send email tojava-ee-j2ee-programming-with-passion@googlegroups.comTo unsubscribe from this group, send email tojava-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.comFor more options, visit this group athttp://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en





-- 
You received this message because you are subscribed to the Google
Groups "Java EE (J2EE) Programming with Passion!" group.
To post to this group, send email to
java-ee-j2ee-programming-with-passion@googlegroups.com
To unsubscribe from this group, send email to
java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en


Re: [java ee programming] ParseDouble problem

2011-07-16 Thread John Masseria
Take a look at NumberFormat:

http://download.oracle.com/javase/1,5.0/docs/api/java/text/NumberFormat.html


public abstract class *NumberFormat*extends Format


NumberFormat is the abstract base class for all number formats. This class
provides the interface for formatting and parsing numbers. NumberFormat also
provides methods for determining which locales have number formats, and what
their names are.

NumberFormat helps you to format and parse numbers for any locale. Your code
can be completely independent of the locale conventions for decimal points,
thousands-separators, or even the particular decimal digits used, or whether
the number format is even decimal.

To format a number for the current Locale, use one of the factory class
methods:

  myString = NumberFormat.getInstance().format(myNumber);


If you are formatting multiple numbers, it is more efficient to get the
format and use it multiple times so that the system doesn't have to fetch
the information about the local language and country conventions multiple
times.

 NumberFormat nf = NumberFormat.getInstance();
 for (int i = 0; i < a.length; ++i) {
 output.println(nf.format(myNumber[i]) + "; ");
 }


To format a number for a different Locale, specify it in the call to
getInstance.

 NumberFormat nf = NumberFormat.getInstance(Locale.FRENCH);


You can also use a NumberFormat to parse numbers:

 myNumber = nf.parse(myString);


2011/7/16 Rafał Laczek 

> Hi Colleagues,
>
> In my application I have input string field.
> String resultStr is parsed into double.
> The problem is when resultStr is with "comma" eg. 2,3 instead of 2.3 (with
> dot).
> Can I solve it in any way?
> Bellow is my current code.
> double resultDoub =Double.parseDouble(resultStr);
>
> Thanks in advance for advice.
>
> Regards,
> Rafal
>
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Java EE (J2EE) Programming with Passion!" group.
> To post to this group, send email to
> java-ee-j2ee-programming-with-passion@googlegroups.com
> To unsubscribe from this group, send email to
> java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com
> For more options, visit this group at
>
> http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Java EE (J2EE) Programming with Passion!" group.
To post to this group, send email to
java-ee-j2ee-programming-with-passion@googlegroups.com
To unsubscribe from this group, send email to
java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en