Case sensitiveness in NumberFormat ?

Discussion in 'Java' started by mtp, Jun 14, 2006.

  1. mtp

    mtp Guest

    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");
    }
    }
    }
     
    mtp, Jun 14, 2006
    #1
    1. Advertisements

  2. Thomas Weidenfeller, Jun 14, 2006
    #2
    1. Advertisements

  3. mtp

    mtp Guest

    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.