Decimal.Parse / Double.Parse Returns a value without a decimal point

I work with workflows in Sharepoint 2007. In Workflow, I go to the Inforpath Code Behind form and add some duplicate values ​​to the Sharepoint list.

string strProfitMargin = ProfitMargin; decimal margin1 = decimal.Parse(strProfitMargin); listItem["Test9"] = Math.Round(margin1, 2).ToString(); 

Suppose for ProfitMargin I get the value "0.4230769230769231" .

Decimal.Parse Returns method 4230769230769231 without a decimal point. Ultimately, Math.Round also does not work. This works great on my machine. But it does not work on QA servers. Please help me and explain why the decimal.Parse method does not work? The same path for double.Parse () returns a value without a decimal.

Thanks in advance!

+4
source share
1 answer

My strong suspicion is that you are working on a machine with a crop that does not use . as a decimal point.

Define a culture explicitly, for example. to invariant culture

 decimal margin1 = decimal.Parse(strProfitMargin, CultureInfo.InvariantCulture); 
+6
source

Source: https://habr.com/ru/post/1484443/


All Articles