« Reply #1 on: February 11, 2024, 09:34:00 PM »
Something like this will probably suit me better.
[CommandMethod("Test0212")]
public void Test0212()
{
if (TryIsValueIntegral(101, out int a))
WriteMessage("\na: " + a);
if (TryIsValueIntegral(11.42, out int b))
WriteMessage("\nb: " + b);
if (TryIsValueIntegral("22", out int c))
WriteMessage("\nc: " + c);
if (TryIsValueIntegral("22.42", out int d))
WriteMessage("\nd: " + d);
if (TryIsValueIntegral(1111.00, out int e))
WriteMessage("\ne: " + e);
if (TryIsValueIntegral("122.00", out int f))
WriteMessage("\nf: " + f);
}
bool TryIsValueIntegral(double dvalue, out int ivalue)
{
ivalue = (int)Math.Round(dvalue, 4, MidpointRounding.AwayFromZero);
return Math.Abs(dvalue - ivalue) < 1e-16;
}
bool TryIsValueIntegral(string svalue, out int ivalue)
{
if (double.TryParse(svalue, out double cvalue))
{
ivalue = (int)Math.Round(cvalue, 4, MidpointRounding.AwayFromZero);
return Math.Abs(cvalue - ivalue) < 1e-16;
}
else
{
ivalue = 0;
return false;
}
}
Command: TEST0212
a: 101
c: 22
e: 1111
f: 122
Now I just need to parse the resultBuffers ( tomorrow or next )
« Last Edit: February 12, 2024, 03:48:20 AM by kdub_nz »
Logged
Called Kerry in my other life
Retired; but they dragged me back in !
I live at UTC + 13.00
---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.