🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #18787

Re: String Conversions

#18787
From: Julio Rincon
Date: Wed, 29 Apr 1998 00:00
46 lines
1902 bytes
After many hours I found a solution using the following:

Float f = new Float("0.00");
f = Float.valueOf(string);
int p = f.intValue();

Thanks for your comments, I hadn't thought of using the integer class
as you indicated.

Julio.

On Tue, 28 Apr 1998 17:44:29 -0700, Clint Brewer
<supportinfo@borland.com> wrote:

>>   String test = fieldOne.getText();
>>   int itest = Integer.parseInt(test);
>>   String stest = Integer.toString(itest);
>>   fieldTwo.setText(stest);
>
>Hello Julio,
>
>  Yeah, I got mixed up on this in the past when i was trying to do a lot
>of conversions as well.  I found that the easiest way to do the
>conversion from string to a float or int was to use the Integer class
>or the Float class.
>
>  The constructor for these classes takes a string as an argument if you
>want, and then converts it into a int or float.  
>
>  For instance you could do something like..
>
>   Integer Field1_int=new Integer(fieldOne.getText());
>   
>   then, the Integer class has plenty of utility functions to play with
>that integer.
>
>   As far as the currency, 55.55 is a float and shouldn't be used with
>an int.  
>
>   If you pass "55.55" to the Integer constructor, I believe it should
>throw a NumberFormatException.  You could then catch that and tell the 
>user to enter an int and not a float, or something along those lines.
>
>hope this helps,
>Clint Brewer
Technical Details
Message-ID: <3546eda1.1040292480@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <3544318b.861070400@forums.borland.com> <354677ED.4D71@borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,896ae2f6a10aacdf
X-Google-Attributes: gidf74b3,public
From: julioCR@aol.com (Julio Rincon)
Subject: Re: String Conversions
Date: 1998/04/29
Message-ID: <3546eda1.1040292480@forums.borland.com>
X-Deja-AN: 348654802
References: <3544318b.861070400@forums.borland.com> <354677ED.4D71@borland.com>
Organization: Another Netscape Collabra Server User
Newsgroups: borland.public.jbuilder.java.language