Xref: utcsri ut.cdf.csc108h:359
Path: utcsri!cs.toronto.edu!craig
Newsgroups: ut.cdf.csc108h
From: craig@cs.toronto.edu (Craig MacDonald)
Subject: Converting from String to primitive numeric types
X-Nntp-Posting-Host: qew.cs.toronto.edu
Message-ID:
X-Newsreader: NN version 6.5.0 #8 (NOV)
Date: 19 Sep 97 17:14:23 GMT
Lines: 25
String string;
/* I assume you have an object of class String
called string which has a value
that is consistent with the primitive type i.e string = "1.5"; */
double d = new Double(string).doubleValue();
// OR
double dd = Double.valueOf(string).doubleValue();
// for float i.e. string = "1.5f";
float f = new Float(string).floatValue();
// OR
float ff = Float.valueOf(string).floatValue();
/* no decimal point here i.e. string = "12345";
int i = Integer.parseInt (string);
If you have trouble understanding these ask me or a TA or reply to this post.
Craig Mac Donald