Double.TryParse() input decimal separator different than system decimal separator

前端 未结 4 1198
眼角桃花
眼角桃花 2021-01-04 14:42

I have a source XML that uses a dot (\".\") as a decimal separator and I am parsing this on a system that uses a comma (\",\") as a decimal separator.

As a result,

4条回答
  •  有刺的猬
    2021-01-04 15:09

    This does the job:

        string test = "0.7";
        Assert.Equal(0.7, Double.Parse(test, NumberStyles.Float, CultureInfo.InvariantCulture));
    

提交回复
热议问题