4

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!

Oded
  • 489,969
  • 99
  • 883
  • 1,009
SPKan
  • 555
  • 2
  • 12
  • 26
  • 1
    `decimal.Parse("0.4230769230769231")` returns `0.4230769230769231` for me. What culture is this running under? – Oded Jun 04 '13 at 15:43
  • Our Servers are in Germany. I think it should be "de-DE". Is that the reason.Thanx. – SPKan Jun 04 '13 at 15:54
  • Yes, most likely. That culture uses `,` for a decimal separator. Parse using `CultureInfo.InvariantCulture` or use a decimal literal that uses `,` instead of a `,`. – Oded Jun 04 '13 at 15:56

1 Answers1

7

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);
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • Thanks I'll try this method. Our Servers are in Germany. But already there are Double.Parse() methods in Web parts which works fine. Thank your for your answer. – SPKan Jun 04 '13 at 15:56