🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Parsing String to Integer

#16711
From: Doug Chamberlin
Date: Sun, 24 Jan 1999 00:00
21 lines
1456 bytes
On Thu, 21 Jan 1999 19:11:09 +0100, Ginny Cheah <gc@consultec.de>
wrote:

>I used parseInt(String) method from Class java.lang.Integer to cast a
>string
>as a signed decimal Integer, however the "0" is being parsed as blank
>(nothing). Is it possible keep the "0" as Integer 0 while using this
>method
>or is there better way of doing it?

Ginny, look up NumberFormat or DecimalFormat classes. You instantiate
one of these using a format pattern and can then use the object to
parse strings of numbers as well as formatting them for display. I
expect you could devise a format pattern string which will do what you
want in handling the zeroes.

Some relevant coding:
DecimalFormat vDF = new DecimalFormat("###0.0000");
String vFactorString = "123.4567";
Double vFactor = vDF.parse(vFactorString,new ParsePosition(0));
double vTemp = vFactor.doubleValue();
Technical Details
Message-ID: <36ad2e31.224619160@forums.inprise.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <36A76DBD.3F6735BD@consultec.de>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,256c646a4b3cb6c9
X-Google-Attributes: gidf74b3,public
From: dchamberlinNOSPAM@dlawton.com (Doug Chamberlin)
Subject: Re: Parsing String to Integer
Date: 1999/01/24
Message-ID: <36ad2e31.224619160@forums.inprise.com>
X-Deja-AN: 436339631
Content-Transfer-Encoding: 7bit
References: <36A76DBD.3F6735BD@consultec.de>
Content-Type: text/plain; charset=us-ascii
Organization: D. Lawton Associates
Mime-Version: 1.0
Reply-To: dchamberlinNOSPAM@dlawton.com
Newsgroups: borland.public.jbuilder.java.language