Hi,
I'm new to this forum and looking forward to future collaboration . I'm developing a C# standalone application for AVEVA that reads ENGITEM data from the AVEVA Engineering databases. When I retrieve attribute values, such as volumetric capacity, the units are in m³/s. However, in the Engineering Interface, users can enter data in US Gallons per Minute (USGPM). Due to the precision being limited to four decimal places (0.0000), I encounter issues when rounding to even numbers.
For example, if a user enters 5000 USGPM in AVEVA Engineering, my C# application retrieves this as 0.3155 m³/s. When I convert this value using my C# method (shown below), the result is 5000.77694436 USGPM. After rounding, it becomes 5001 USGPM, which doesn't look accurate in our reports.
Is there a way in C# to get the value with specified units? Can we force the data to be retrieve as USGPM?
public static string ConvertM3PerSecondToUSGPerMinute(string MyValue) { MyValue = MyValue.Replace("m3/s", "").Trim(); // Check if the value is "unset" or empty if (MyValue == "unset" || string.IsNullOrEmpty(MyValue)) { return string.Empty; } if (double.TryParse(MyValue, out double myValue)) { if (myValue == 0) { return string.Empty; } double cubicMeterToUSGallon = 264.172052; double secondsToMinutes = 60; double myFinalOut = myValue * cubicMeterToUSGallon * secondsToMinutes; // Round to 1 decimal place myFinalOut = Math.Round(myFinalOut,1, MidpointRounding.ToEven); //myFinalOut = Math.Round(myFinalOut / 5) * 5; StringBuilder sb = new StringBuilder(); sb.AppendFormat("{0}USG/min", myFinalOut); return sb.ToString(); } else { return string.Empty; } }
ele.GetAsString(myAttribute)