Hello,
When I use Rhino.UI.Localization.FormatNumber
I get unexpected results and am trying to figure out if it’s me or the API method.
Based on my debug prints below it would appear that the method correctly parses floats with a single decimal place and inserts the -
symbol but fails to do so on numbers greater than single decimal.
Furthermore, when the result is less than 1’ it returns inches instead of 0'-inches number here"
which is (I believe?) more standard in representing Architectural feet/inches in drawings.
Input:
elevation_from_data: 0
scaled_elevation: 0.0
FormattDistance result: 0"
formatted_elevation: 0"elevation_from_data: 0.15239999999999998
scaled_elevation: 0.49999999999999994
FormattDistance result: 6"
formatted_elevation: 6"elevation_from_data: 4.267199999999999
scaled_elevation: 13.999999999999996
FormattDistance result: 14’0"
formatted_elevation: 14’0"elevation_from_data: 7.924799999999999
scaled_elevation: 26.0
FormattDistance result: 26’-0"
formatted_elevation: 26’-0"elevation_from_data: 11.582399999999998
scaled_elevation: 37.99999999999999
FormattDistance result: 38’0"
formatted_elevation: 38’0"elevation_from_data: 15.239999999999998
scaled_elevation: 49.99999999999999
FormattDistance result: 50’0"
formatted_elevation: 50’0"Expectation:
38’-0"
26’-0"Result:
![]()
Expectation:
38’-0"
0’-6"Result:
![]()
Code:
def FormatDistance(distance):
"""Given a number in model units, format to display in feet / inches (fractional)"""
try:
# inches = Rhino.UnitSystem.Inches
model_units = scriptcontext.doc.ActiveDoc.ModelUnitSystem
feetInches = Rhino.UI.DistanceDisplayMode.FeetInches
precision = 4
formatted_number = Rhino.UI.Localization.FormatNumber(distance, model_units, feetInches, precision, False)
print(f"FormattDistance result: {formatted_number}")
return formatted_number
except Exception as ex:
Rhino.RhinoApp.WriteLine(f"Utils.FormatDistance Exception: {ex}")
Thanks for your help!