Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decimal.Parse/Double.Parse Returns a Value without the Decimal Point

I am working with workflows in Sharepoint 2007. In the Workflow I am accessing a Inforpath form the Code Behind and add some Recurring values to a Sharepoint List.

string strProfitMargin = ProfitMargin;

decimal margin1 = decimal.Parse(strProfitMargin);

listItem["Test9"] = Math.Round(margin1, 2).ToString();

Suppose for the ProfitMargin I get a value "0.4230769230769231".

Decimal.Parse Method Returns 4230769230769231 without the Decimal point. Ultimately Math.Round also not working. This works perfectly in my machine. But in QA servers Its not Working. Please Help me and Explain why the decimal.Parse method not Working? Same Way for double.Parse() is returning a value without a decimal.

Thanks in Advance!

like image 807
SPKan Avatar asked Mar 23 '23 17:03

SPKan


1 Answers

My strong suspicion is that you're running on a machine with a culture which doesn't use . as a decimal point.

Specify the culture explicitly, e.g. to the invariant culture

decimal margin1 = decimal.Parse(strProfitMargin, CultureInfo.InvariantCulture);
like image 53
Jon Skeet Avatar answered Apr 06 '23 09:04

Jon Skeet