M
mtp
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");
}
}
}
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");
}
}
}