By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,480 Members | 755 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,480 IT Pros & Developers. It's quick & easy.

Decimal conversion problem

P: 14
I am doing decimal conversion in my code as below

if datachNode.InnerText is "147.00" and scaleFactor.InnerText is "1"

decimal value = Convert.ToDecimal(datachNode.InnerText.ToString()) ;
decimal scale = Convert.ToDecimal(scaleFactor.InnerText.ToString() );
decimal scaledValue = value / scale;
string decimaladjust = scaledValue.ToString("N2");
string headerStr = "\"" + decimaladjust + "\"";

But my colleague getting different answers in sweden

COuld anybody help me to resolve it ?
Mar 10 '09 #1
Share this Question
Share on Google+
1 Reply


P: 40
Add

Expand|Select|Wrap|Line Numbers
  1. System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("sv-SE");
to the start of your code (and change 147.00 to 147,00) and you get same result as your colleague.

So, the catch is, Convert.ToDecimal uses current culture's rules for number parsing, and if nothing is specified, current culture is the one specified on the operarting system.
Mar 10 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.