Is there any function like int() which can convert a string to float value?
I’m currently using the following code:
$input=int(substr($line,1,index($line,",")-1));
I need to convert the string returned by substr to float.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Just use it. In Perl, a string that looks like a number IS a number.
Now, if you want to be sure that the thing is a number before using it then there’s a utility method in
Scalar::Utilthat does it:Based on the sample input you left in the comments, a more robust method of extracting the number is: