I try to read some weight values from a mettler toledo weighing machine via serial port. When i convert the string i get from serial port to double it puts the dot to wrong place. It converts 144.95 to 14495.0. How can i convert this string to correct double value ?
if (this.InvokeRequired)
{
// Using this.Invoke causes deadlock when closing serial port,
// and BeginInvoke is good practice anyway.
this.BeginInvoke(
new EventHandler<SerialDataEventArgs>(spManager_NewSerialDataRecieved),
new object[] { sender, e });
return;
}
string pattern = @"\s.(\d+\.\d{2})(\sg\r\n(S\sS\s.)?)?$";
string data = Encoding.ASCII.GetString(e.Data);
MatchCollection mc = Regex.Matches(data, pattern);
if (mc.Count > 0)
{
if (tartim)
{
double weight = Convert.ToDouble(mc[0].Groups[1].Value); //Wrong conversion
if (weight > weightLowerLimit && weight < weightUpperLimit)
{
MoveToNextSlot();
}
}
}