DbDouble
- Last UpdatedJun 02, 2022
- 2 minute read
Represents a real dimensioned quantity which can be constructed from an expression and/or a format or returned from DbElement. For example, create a DbDouble from a real value
DbDouble d1 = DbDouble.Create(1.0);
or create a DbDouble from a string expression
DbDouble d1 = DbDouble.Create("1.0kg");
or get a dimensioned attribute from DbElement as a DbDouble
DbElement bran = DbElement.GetElement("/100-B-1-B1");
DbDouble hbor = bran.GetDbDouble(DbAttributeInstance.HBOR);
DbDouble's may also be used to set dimensioned attributes. For example, setting the HBOR of a branch
DbElement bran = DbElement.GetElement("/100-B-1-B1");
DbDouble hbor = DbDouble.Create("300", fbore)
bran.SetAttribute(DbAttributeInstance.HBOR, hbor);
Quantities of dimension BORE may be created as follows from a real value
DbDouble bore = DbDouble.CreateBore(300);
or a string expression and a format
DbFormat fbore = DbFormat.Create();
fbore.Dimension = DbDoubleDimension.GetDimension(DbDimension.DIST);
fbore.Units = DbDoubleUnits.GetUnits(DbUnits.FINC);
DbDouble bore = DbDouble.CreateBore("12", fbore);
returning the nearest nominal bore depending on the current BORE units. There are also properties to return the units, dimension etc. For example, get the units of given DbDouble
DbDouble d1 = DbDouble.Create("2m");
DbDoubleUnits u1 = d1.Units;
To return a formatted string, For example
DbFormat ftemp = DbFormat.Create();
ftemp.Dimension = DbDoubleDimension.GetDimension(DbDimension.TEMP);
ftemp.Units = DbDoubleUnits.GetUnits("degRankine");
ftemp.Label = "degRan";
DbDouble t1 = DbDouble.Create("3 celsius");
String tempStr = t1.ToString(ftemp);
and to convert to different units
DbDouble d1 = DbDouble.Create("1kg");
DbDouble d2 = d1.ConvertUnits(DbDoubleUnits.GetUnits(DbUnits.LB));
DbDouble also implements the expected binary operator overloads '+', '-', '\', '*', '==', '!=', '<', '<=', '>' and '>=' allowing arithmetic operations and comparison of dimensioned quantities. For example, adding 2 quantities of the same dimension together
d1 = DbDouble.Create("1 kg");
d2 = DbDouble.Create("2.2046 lb");
d3 = d1 + d2;