Reputation: 45
I have a web service on iis. service must return like 34.56 string value. Because in my local service return this value, but when i try this method on iis server methot return 34560000. What is the reason of this problem?
public string GetTotal(string a, string b)
{
double total= 0;
List<BorcLite> bList = GetTotalList(a, b);
if (bList.Count == 0)
return total.ToString();
if (bList[0].resultCode != "0")
return bList[0].resultCode;
foreach (BorcLite record in bList)
{
total+= Convert.ToDouble(record.totalBill);
}
return total.ToString();
}
Upvotes: 0
Views: 75
Reputation: 14591
Convert.ToDouble
uses current thread culture.
You probably use different locales on your systems.
Solution is to use appropriate culture by calling the overload of Convert.ToDouble
which takes IFormatProvider
as argument:
string s = "34,56000";
double d = Convert.ToDouble(s); // my default US -> 3456000
d = Convert.ToDouble(s, CultureInfo.InvariantCulture); // -> 3456000
d = Convert.ToDouble(s, CultureInfo.GetCultureInfo("en-US")); // -> 3456000
d = Convert.ToDouble(s, CultureInfo.GetCultureInfo("de-DE")); // -> 34.56
Upvotes: 1