UOMGroup.Convert Method
- Last UpdatedJan 12, 2026
- 4 minute read
- PI System
- AF SDK 3.2.0
- Developer
Namespace: OSIsoft.AF.UnitsOfMeasure
Assembly: OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 3.2.0.7
Syntax
public double Convert( Object fromValue, UOM fromUOM )
Public Function Convert ( fromValue As Object, fromUOM As UOM ) As Double Dim instance As UOMGroup Dim fromValue As Object Dim fromUOM As UOM Dim returnValue As Double returnValue = instance.Convert(fromValue, fromUOM)
public: double Convert( Object^ fromValue, UOM^ fromUOM )
member Convert : fromValue : Object * fromUOM : UOM -> float
Parameters
- fromValue
- Type: SystemObject
The value to be converted. Normally, this is sent as a double. - fromUOM
- Type: OSIsoft.AF.UnitsOfMeasureUOM
The unit of measure of the specified value. If this is not specified, or is specified, then the unit of measure should be specified in the fromValue by passing it as a string.
Return Value
Type: DoubleReturns the value converted to the mapped unit of measure as defined by this UOMGroup.
Exceptions
| Exception | Condition |
|---|---|
| InvalidCastException | Thrown when the conversion cannot be performed. |
Remarks
The mappings defined for this UOMGroup are used to determine resulting UOM for the fromValue based upon the specified fromUOM. If the two UOMs share the same reference object, or are a direct reference to each other, then the conversion is done directly using these reference units. This allows fewer mathematical operations and reduces the loss of precision during conversion. Otherwise, the canonical unit-of-measure factors are used to convert.
Optionally, you can specify for the fromUOM parameter and specify the units in the input parameter if it is represented in string notation. For example, "100.0 ft". In this case, the Convert function looks up the UOM from the text name or abbreviation that follows the floating point number.
Examples
// This example will create a UOM Group with mappings, display its information, // and then perform some conversions. // Get the Database PISystems myPISystems = new PISystems(); UOMDatabase myDB = myPISystems.DefaultPISystem.UOMDatabase; // Create a UOM Group UOMGroup MyCustomGroup = myDB.UOMGroups.Add("MyCustomUOMGroup*"); MyCustomGroup.Description = "Custom UOM Group for Length"; // Add mappings to group MyCustomGroup.Mappings[myDB.UOMs["ft"]] = myDB.UOMs["m"]; MyCustomGroup.Mappings[myDB.UOMs["in"]] = myDB.UOMs["cm"]; MyCustomGroup.Mappings[myDB.UOMs["nmi"]] = myDB.UOMs["km"]; MyCustomGroup.Mappings[myDB.UOMs["mi"]] = myDB.UOMs["km"]; MyCustomGroup.Mappings[myDB.UOMs["mm"]] = myDB.UOMs["cm"]; MyCustomGroup.Mappings[myDB.UOMs["sxi"]] = myDB.UOMs["cm"]; MyCustomGroup.Mappings[myDB.UOMs["yd"]] = myDB.UOMs["m"]; myDB.CheckIn(); // Display the UOM Groups foreach (UOMGroup group in myDB.UOMGroups) { Console.WriteLine("Name of UOM Group = {0}", group.Name); Console.WriteLine("Description = {0}", group.Description); Console.WriteLine("Mappings:"); foreach (KeyValuePair<UOM, UOM> item in group.Mappings) { Console.WriteLine(" {0} ==> {1}", item.Key, item.Value); } } // Perform some conversions AFValue origAFValue = new AFValue(55.3, AFTime.Now, myDB.UOMs["mi"]); double mappedValue = MyCustomGroup.Convert(100.0, myDB.UOMs["yd"]); Console.WriteLine("Convert 100.0 ft ==> {0}", mappedValue); AFValue mappedAFValue = origAFValue.Convert(MyCustomGroup); Console.WriteLine("Convert {0} {1} ==> {2} {3}", origAFValue.Value, origAFValue.UOM, mappedAFValue.Value, mappedAFValue.UOM); // Display attribute value using Display UOM myDB.DisplayUOMGroup = MyCustomGroup; origAFValue = MyAttr.GetValue(); mappedAFValue = MyAttr.GetValue(MyAttr.DisplayUOM); Console.WriteLine("GetValue {0} {1} ==> {2} {3}", origAFValue.Value, origAFValue.UOM, mappedAFValue.Value, mappedAFValue.UOM);