Article View: borland.public.jbuilder.java.language
Article #16279How to deal with numbers as strings?
From: MTDINC
Date: Mon, 15 Mar 1999 00:00
Date: Mon, 15 Mar 1999 00:00
34 lines
1778 bytes
1778 bytes
Hello,
I am working on this right now but am having some problems. I have to
compare part numbers that can be of any combination of numbers only,
numbers and letters, numbers/letters/symbols (such as - or .), or
letters only. The following code illustrates this:
1. String partNumber;
2. String PNString = "100.099999";
3. String PNS;
4. Label label1 = new Label();
5. partNumber = dataRow.getString(PN);
6. if(partNumber != PNString){
7. PNS = "Not equal";
8. }
9. label1.setText(partNumber + "." + PNS);
I access a database with a part number (declared as "string" in the
schema) in line 5. When the code gets to line 6 it fails the comparison,
but the two strings are the same. The label is painted with:
"100.099999. Not equal"
It can be seen that the number stored as a string in line 2 is the same
as that obtained from the database but they are found not equal in line
6. When real alphabetic strings are compared (that are the same) there
is no problem.
So, how are strings supposed to be handled that can contain non-number
or non-alphabetic characters? I've looked through the on-line Help but
find nothing pertaining to this casting.
Thanks, Jeff Biss
Technical Details
Message-ID:
<36EDC210.93F64477@earthlink.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,e43a7f1f5e26c52b,start X-Google-Attributes: gidf74b3,public From: MTDINC <mtdinc@earthlink.net> Subject: How to deal with numbers as strings? Date: 1999/03/15 Message-ID: <36EDC210.93F64477@earthlink.net> X-Deja-AN: 455502287 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii Organization: Another Netscape Collabra Server User Mime-Version: 1.0 Reply-To: mtdinc@earthlink.net Newsgroups: borland.public.jbuilder.java.language