Hi all,
Thanks for your time first of all. Strictly speaking this is not a Revit API issue I'm facing but after some research I couldn't find the answer here or anywhere else but it's still a challenge related to Revit.
I'm comparing a family parameter value with values in a spreadsheet so I can update the parameter accordingly if they don't match but I'm getting weird results when comparing them. The snippet below shows how I'm extracting the double value of the WW_Width parameter and converting it to millimetres. Then I compare it to the a parsed string with the exact same value as a double but I get a false result to whether or not they match.
var famPars = doc.FamilyManager.Parameters;
var famTypes = doc.FamilyManager.Types;
foreach (FamilyParameter param in famPars)
{
foreach (FamilyType famtype in famTypes)
{
if (param.Definition.Name == "WW_Width")
{
console.ShowBoldMessage("WW_Width");
console.ShowMessage($"UnitType: {param.Definition.UnitType}");
console.ShowMessage($"StorageType: {param.StorageType}\n");
double valueInMM = UnitUtils.ConvertFromInternalUnits((double)famtype.AsDouble(param),
DisplayUnitType.DUT_MILLIMETERS);
double parsedString = double.Parse("2448");
console.ShowMessage($"Value: {valueInMM}");
console.ShowMessage($"Parsed string: {parsedString}");
console.ShowMessage($"Values match: {valueInMM == parsedString}");
}
}
}
This is what my console shows as a result but I don't get why I'm getting a mismatch.
WW_Width
UnitType: UT_Length
StorageType: Double
Value: 2448
Parsed string: 2448
Values match: False
Solved! Go to Solution.
Solved by jeremy_tammik. Go to Solution.
You need to add some fuzz:
https://www.google.com/search?q=fuzz&as_sitesearch=thebuildingcoder.typepad.com
@jeremy_tammik Thanks for the steer in the right direction. I wasn't aware of that issue with doubles/floats. Instead of directly comparing the doubles, I'm subtracting one from the other and checking if the difference is under a certain tolerance (e.g. A - B < 0.001) and that works.
This article explains it well in case anyone faces this issue in the future.
Brilliant! Glad that it helped, and thank you for the appreciation and nice helpful pointer.
I'm always very thankful to these forums and the help I get here as I have no one around me to ask these questions to when I'm stuck.