We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Type Conversion (Read 1438 times)
Type Conversion
Jan 17th, 2008, 5:44am
 
Hi

Just starting to learn processing from the recent book. I'm trying to use financial data from the yahoo quotes url to graphically display price changes etc (as a learning tool). I have a very basic question - I can get the price data for a stock (eg. GOOG) , but it is of String type, and I can't convert it into float type to draw a graphic object with...


String URL = "http://finance.yahoo.com/d/quotes.csv?s=GOOG&f=p";
String[] data;
//float result = 10.2;
float result = float(data)

void setup(){
 size(100,100);
 data = loadStrings(URL);
 println(data);
// println(data.length);
}

void draw() {
 stroke(255);
 line(50, 90, 50, result);
}

Thanks in advance!

CLS
Re: Type Conversion
Reply #1 - Jan 17th, 2008, 6:30am
 
I'm sure there is an easier way but here's a simple way of doing it. It simply copies each value of the string array and converts it to a float.

Code:
String URL = "http://finance.yahoo.com/d/quotes.csv?s=GOOG&f=p";  
String[] data;
float[] dataConverted;
float result = 10.2;

void setup(){
size(100,100);
data = loadStrings(URL);
println(data);

dataConverted = new float[data.length];

for (int i = 0; i < data.length; i++){
dataConverted[i] = float(data[i]);
}

println(dataConverted);
}

void draw() {
stroke(255);
line(50, 90, 50, result);
}
Page Index Toggle Pages: 1