Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2006

Tip: Looking for answers? Try searching our database.

Case sensitiveness in NumberFormat ?

Thread view: 
mtp - 14 Jun 2006 10:37 GMT
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 :)


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.