convert string into decimal

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • doll
    New Member
    • Jul 2007
    • 24

    convert string into decimal

    hi
    i want to convert a number(string) into decimal in vb.net...

    for eg:
    if i input 1 it should be converted to 1.0
    please help me..please give me the code for it...

    thanking you
    Last edited by doll; Aug 1 '07, 05:15 AM. Reason: dint mention the language in which i want the code
  • santuvssantu
    New Member
    • Jun 2007
    • 12

    #2
    Hi,
    Use Convert.ToDecim al() function.

    Thanks.

    Comment

    • doll
      New Member
      • Jul 2007
      • 24

      #3
      Originally posted by santuvssantu
      Hi,
      Use Convert.ToDecim al() function.

      Thanks.
      hi
      thanks for your suggestion..but that function is not working in visual studio 2005...so please suggest something else..if possible the entire code...

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        You could try Decimal.Parse() (or Float.Parse() or Double.Parse())
        Check the MSDN help on it for more information on the commands

        Comment

        • ammoos
          New Member
          • Apr 2007
          • 100

          #5
          you can use either the format

          string number = "122";
          decimal result =Convert.ToDeci mal((Convert.To Decimal(number) ).ToString("N", new CultureInfo("en-GB")));


          or
          string number = "122";
          decimal result =Convert.ToDeci mal((Convert.To Decimal(number) ).ToString(".00 "));

          Comment

          • erlin
            New Member
            • Jul 2007
            • 5

            #6
            The CInt function might help you.

            CInt("1")

            and many more conversions are available starting with C... (CDlb -- to convert to double, etc)

            Comment

            • Plater
              Recognized Expert Expert
              • Apr 2007
              • 7872

              #7
              You will need to make the constructors as vb, but:
              Code:
              string mydecimal="12.8";
              Decimal d= Decimal.Parse(mydecimal);
              //d is now equal to 12.8

              Comment

              Working...