Convert string with commas to float

前端 未结 9 2102
走了就别回头了
走了就别回头了 2021-02-19 18:58

Is there a built-in Delphi function which would convert a string such as \'3,232.00\' to float? StrToFloat raises an exception because of the comma. Or is the only way to stri

9条回答
  •  情深已故
    2021-02-19 19:28

    Using Foreach loop

     public static float[] ToFloatArray()
        {
         string pcords="200.812, 551.154, 232.145, 482.318, 272.497, 511.752";
    
          float[] spiltfloat = new float[pcords.Split(',').Length];
            int i = 0;
            foreach (string s in pcords.Split(','))
            {
               spiltfloat[i] = (float)(Convert.ToDouble(s));
                i++;
            }
            return spiltfloat;
        }
    

提交回复
热议问题