Convert a String to Float in C# - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Convert a String to Float in C#

su_di_ptosu_di_pto Posts: 5Member
How do i convert a string value to corresponding float value in C#?

Comments

  • pingpongpingpong Posts: 937Member
    : How do i convert a string value to corresponding float value in C#?
    :
    [code]
    string s = "124.53";
    try
    {
    float f = (float)double.Parse(s);
    }
    catch(FormatException ex)
    {
    // handle error here (if s is empty, has characters, etc)
    }
    [/code]
Sign In or Register to comment.