I need help again lol, im trying to code a load function, ive got it to read the files and put the values into strings, but i need to convert these to float type and nothing i try seems to work!
Primitive types have wrapper classes, such as Float for float. Each of numberlike ones have parsing methods, that turn a suitable String to that type of number, eg. Float.parseFloat(...)
When you say winStat is coming up empty what exactly do you mean? ie how have you determined it is empty and what type is winStat? ie is it a float or a Float.
Last edited by keang; January 12th, 2009 at 04:43 PM.
Reason: typo
Print out the value of trans1 please. I have a feeling you have something in there that isn't valid. I ran the following program with the following results so I know that it isn't Java or the Float class:
Code:
public class ConvertStringToFloat {
public static void main(String[] args) {
String number = "8945.342";
Float f1 = new Float(number);
System.out.println("f1: " + f1.floatValue());
float f2 = Float.valueOf(number);
System.out.println("f2: " + f2);
float f3 = Float.parseFloat(number);
System.out.println("f3: " + f3);
}
}
Code:
f1: 8945.342
f2: 8945.342
f3: 8945.342
Paste the code for the winstat variable and what it is supposed to do.
Print out the value of trans1 please. I have a feeling you have something in there that isn't valid
I agree we need more info from the OP but if trans1 is not valid then trying to convert it to a float will result in a NumberFormatException being thrown. Of course, I suppose it's possible the OP is catching and ignoring exceptions and so doesn't even know an exception has been raised or does know and has just neglected to tell us.
Ok apologies, i have been working with swing, and its not showing the stats on swing however they are being uploaded! Im not sure why there not showing up on my swing program though
Bookmarks