How to convert string to single???

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JH-PRO

    How to convert string to single???

    Please help!

    How to convert string to single

    Here my start values:

    Dim My_string as string = "29.02"
    Dim My_single as single = 0.0


    i try this way but i get error

    My_single = CSng(My_string )


    Conversion from string "29.02" to type 'Single' is not valid.

    Thanx

    Jalmari


  • John Devlon

    #2
    Re: How to convert string to single???





    Hi Jalmari

    use this ...

    My_single = Convert.ToSingl e(My_string)

    John





    "JH-PRO" <jhpro2000@REM_ THIS_hotmail.co mwrote in message
    news:46a618ee$0 $9932$9b536df3@ news.fv.fi...
    Please help!
    >
    How to convert string to single
    >
    Here my start values:
    >
    Dim My_string as string = "29.02"
    Dim My_single as single = 0.0
    >
    >
    i try this way but i get error
    >
    My_single = CSng(My_string )
    >
    >
    Conversion from string "29.02" to type 'Single' is not valid.
    >
    Thanx
    >
    Jalmari
    >

    Comment

    • Fabio

      #3
      Re: How to convert string to single???

      "JH-PRO" <jhpro2000@REM_ THIS_hotmail.co mha scritto nel messaggio
      news:46a618ee$0 $9932$9b536df3@ news.fv.fi...
      Please help!
      >
      How to convert string to single
      >
      Here my start values:
      >
      Dim My_string as string = "29.02"
      Dim My_single as single = 0.0
      >
      >
      i try this way but i get error
      >
      My_single = CSng(My_string )
      >
      >
      Conversion from string "29.02" to type 'Single' is not valid.
      This may be done by your decimal separator defined in the control panel that
      is not a ".".

      Use this:

      My_single = Single.Parse(My _string,
      System.Globaliz ation.NumberFor matInfo.Invaria ntInfo)

      --
      Help The New .Net Site! http://www.devbox4.net


      Comment

      • =?ISO-8859-1?Q?G=F6ran_Andersson?=

        #4
        Re: How to convert string to single???

        JH-PRO wrote:
        Please help!
        >
        How to convert string to single
        >
        Here my start values:
        >
        Dim My_string as string = "29.02"
        Dim My_single as single = 0.0
        >
        >
        i try this way but i get error
        >
        My_single = CSng(My_string )
        >
        >
        Conversion from string "29.02" to type 'Single' is not valid.
        >
        Thanx
        >
        Jalmari
        >
        There is no conversion directly from a string to a single, as a string
        is not a numeric type. What you have to do is to parse the string. There
        are some different methods for that.

        This will just parse the string, and gives an exception if it can't:

        My_single = Single.Parse(My _string)

        This will try to parse the string, and gives you the opportunity to
        handle the situation if it can't be parsed:

        If Single.TryParse (My_string, My_single) Then
        ' ok; My_single contains the value
        Else
        ' could not be parsed
        End If

        --
        Göran Andersson
        _____
        Göran Anderssons privata hemsida.

        Comment

        Working...