- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi!
I'm trying to get areas in square meters. The problem is they need to be always rounded in the exact same way Revit would round them to a precision of 0.01
Here's what I tried:
double valueMeters = UnitUtils.ConvertFromInternalUnits(valueFeet, UnitTypeId.SquareMeters);
string valueMetersRounded = UnitFormatUtils.Format(doc.GetUnits(), SpecTypeId.Area, valueMeters, false);
The problem is that way I would always get the final formatting in accordance with the unit precision set for the project units, which might not always be 0.01
How would one set the precision to be always down to the 0.01, using only the built in API methods? here's a more detailed breakdown of the issue:
It's clearly visible Revit's rounding is inconsistent in some specific border cases, but I need precisely identical results with the ones, visualized in the UI. When using
Math.Round(value, 2, MidpointRounding.AwayFromZero);
All of the specified values will be rounded to 12.12 without exception. This would also be the case with
MidpointRounding.ToEven
etc. So one would always end up with a tiny difference of 0.01 m² in some cases.
This seems like a trivial issue, but is really causing a lot of trouble, e.g. when automating precise area calculations for residential buildings.
Any suggestions would be highly appreciated 🙏
Solved! Go to Solution.