简体   繁体   English

Decimal.Parse / Double.Parse返回不带小数点的值

[英]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. 我正在使用Sharepoint 2007中的工作流程。在工作流程中,我正在访问代码隐藏的Inforpath表单,并将一些重复发生的值添加到Sharepoint列表。

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" . 假设ProfitMargin我得到一个值"0.4230769230769231"

Decimal.Parse Method Returns 4230769230769231 without the Decimal point. Decimal.Parse方法返回4230769230769231不带小数点。 Ultimately Math.Round also not working. 最终Math.Round也无法正常工作。 This works perfectly in my machine. 这在我的机器上完美运行。 But in QA servers Its not Working. 但在QA服务器中它不起作用。 Please Help me and Explain why the decimal.Parse method not Working? 请帮助我解释为什么decimal.Parse方法不工作? Same Way for double.Parse() is returning a value without a decimal. Double.Parse()的相同方式返回一个没有小数的值。

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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