简体   繁体   中英

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!

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, eg to the invariant culture

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM