Parse value with Currency symbol

前端 未结 5 1963
耶瑟儿~
耶瑟儿~ 2021-01-21 13:58

I have looked to multiple SO questions on parsing currency, the best (recommended) way seems to be the one I\'m trying below:

var payout = decimal.Parse(\"$2.10\         


        
5条回答
  •  日久生厌
    2021-01-21 14:35

    Pertinent to your particular case, you may use the following code snippet:

    var payout = decimal.Parse("$2.10".Replace("$",""));
    

    If you don't know what the currency symbol would be, then try the following solution:

    string _money = "$2.10";
    var payout = decimal.Parse(_money.Substring(1));
    

    Dealing with commas and decimal points is much more difficult: if this is the issue, refer to the solution given by member @un-lucky.

    Hope this may help.

提交回复
热议问题