Convert currency string to decimal?

后端 未结 6 935
北恋
北恋 2020-12-05 13:00

Objective

Sort a string that is displaying currency data like this $1,995.94 numerically in a set of data.

Code

I\'m cu

6条回答
  •  南笙
    南笙 (楼主)
    2020-12-05 13:22

    works for all culture:

    var d = decimal.Parse("$497.7", NumberStyles.Currency, CultureInfo.CreateSpecificCulture("us-US").NumberFormat);    
    
    Console.WriteLine(d);
    

提交回复
热议问题