Case sensitiveness in NumberFormat ?

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top