Given a string like: "0.123, 0.456" what is the simplest way to parse the two float values into two variables a and b?
Given a string like: 0.123, 0.456 what is the simplest way to parse the
Share
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.
I would suggest:
string.Split)string.Trim)float.Parseorfloat.TryParse. (If you want an exception to be thrown if the format is incorrect, go forParse. If you want to handle parsing failures as part of your normal control flow, useTryParse.)If the numbers are definitely going to be in that format, explicitly specify
CultureInfo.InvariantCulture. Also consider usingdecimal(ordouble) instead offloat.