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

前端 未结 4 1208
眼角桃花
眼角桃花 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:26

    Easy way to specify custom decimal separator:

    var price = "122$00";
    var nfi = new NumberFormatInfo { CurrencyDecimalSeparator = "$" };
    var ok = decimal.TryParse(price, NumberStyles.Currency, nfi, out result);
    

提交回复
热议问题