Hello,
i've done a small program (see below) which parse a string representing
a real. How can i "say" to NumberFormat to accept to use "e" instead of
"E" ?
parsing of 1e10 = 1 <========= problem
parsing of .1E10 = 1000000000
parsing of 1E40 = 1.0E40
parsing of 1E-10 = 1.0E-10
=================================================================
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Locale;
public class TestNfLocale {
public static void main(String[] args) {
parse("1e10", Locale.US);
parse(".1E10", Locale.US);
parse("1E40", Locale.US);
parse("1E-10", Locale.US);
}
private static void parse(String s, Locale l) {
NumberFormat nf = NumberFormat.getInstance(l);
try {
Number n = nf.parse(s);
System.err.println("parsing of " + s + " = " + n);
} catch (ParseException ex) {
System.err.println("parsing of " + s + " failed");
}
}
}
Thomas Weidenfeller - 14 Jun 2006 10:44 GMT
> i've done a small program (see below) which parse a string representing
> a real. How can i "say" to NumberFormat to accept to use "e" instead of
> "E" ?
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#replaceAll(java.la
ng.String,%20java.lang.String)
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#toUpperCase()
/Thomas

Signature
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/
mtp - 14 Jun 2006 11:26 GMT
Thomas Weidenfeller a écrit :
>> i've done a small program (see below) which parse a string
>> representing a real. How can i "say" to NumberFormat to accept to use
[quoted text clipped - 3 lines]
>
> http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#toUpperCase()
thx :)