I am wondering why this is working:
doubleValue = double.Parse(input[0].ToString(System.Globalization.CultureInfo.InvariantCulture).Replace(',', '.'), System.Globalization.CultureInfo.InvariantCulture);
while this isn't:
doubleValue = Convert.ToDouble(input[0])
The point is, there are about 30 machines in one country (same Windows image, same hardware, different location). While the first 20 machines are fine with Convert.ToDouble()
, the 10 other ones can't convert the values properly (They loose the decimal point in every case, no matter if point or comma).
Since the program is really big an complex, is there an opportunity to get Convert.ToDouble()
working without changing the program itself?
Another point is, i tried different methods to convert my string value to a double, none of them are working but only the double.Parse()
...
And also, is it generally bad to use Convert.ToDouble()
vor strings? (Only for objects)
Edit:
I created this method inside my class:
public static double ToDouble(string value, IFormatProvider provider)
{
if (value == null)
{
return 0.0;
}
return double.Parse(value, NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite | NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands | NumberStyles.AllowExponent, provider);
}
and called it with (tried also points and commas):
doubleValue = ToDouble(myTextBox.Text, CultureInfo.InvariantCulture);
Result: Still not working...
Convert.ToDouble(text,CultureInfo.InvariantCulture)
? – PrismatoiddoubleValue = Convert.ToDouble(myTextBox.Text.Replace('.', ','), System.Globalization.CultureInfo.InvariantCulture);
. Also, it does not matter if it's point to comma or the other way round... – YaluConvert
class, only difference it'sstring
parameter isobject
type. – Allocate465.09
, expected Output (double):465.09
. But the result is46509
... – YaludoubleValue
again, cause I'm testing it and result is465.09
. – Allocate