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.
IndexProgramming Questions & HelpSyntax Questions › convert part of string to numbers
Page Index Toggle Pages: 1
convert part of string to numbers (Read 447 times)
convert part of string to numbers
Jan 16th, 2007, 3:09am
 
Hi all,

I am retreiving data that comes into processing like this "$4.75"
How do I split up 4.75 from $ and turn 4.75 into a float?

I looked at:
http://mobile.processing.org/reference/reference.php?name=split
-but since the $ sign is not seperate from 4.75, then how can I split those two?

Thanks,
GregoRami
Re: convert part of string to numbers
Reply #1 - Jan 16th, 2007, 3:49am
 
Code:

String price = "$100.20";

String sub = price.substring( 1, price.length() );
println( sub );

// Java way

float fprice = Float.parseFloat( sub );
println( fprice );

// or Processing way:

println( float( sub ) );


F
Page Index Toggle Pages: 1