wmayer wrote: ↑Sun Feb 16, 2020 8:50 pm
...
When using a unit then the internal double will be expressed differently and thus behaviour might be unexpected.
...
Thanks for the commit. This should solve the messages in Draft.
However, what you mention, does that not produce a confusing output? It seems to me that the system will try to round the base unit, and not the entered unit. For example, here it displays the millimeters, even when the quantity was expressed in meters.
Code: Select all
>>> q=FreeCAD.Units.Quantity("1.23456789 m")
>>> round(q,0)
1235 mm
>>> round(q,1)
1234.6 mm
>>> round(q,2)
1234.57 mm
>>> round(q,3)
1234.57 mm
>>> round(q,4)
1234.57 mm
>>> round(q,5)
1234.57 mm
>>> round(q,6)
1234.57 mm
In the particular case of angles, it seems to work fine, because angles are usually always within the same range of 0 to 360, and you don't need higher orders of magnitude (1E3, 1E6, 1E9) or lower (1E-3, 1E-6, 1E-9). But that may not be the case for distances, which are often expressed in millimeters all the way to kilometers.
Also, it seems the round operation doesn't show more than five decimals in total. Is that something that can be improved as well?
Code: Select all
>>> q=FreeCAD.Units.Quantity("1.23456789 deg")
>>> round(q, 0)
1 deg
>>> round(q, 1)
1.2 deg
>>> round(q, 2)
1.23 deg
>>> round(q, 3)
1.235 deg
>>> round(q, 4)
1.2346 deg
>>> round(q, 5)
1.23457 deg
>>> round(q, 6)
1.23457 deg
>>> round(q, 7)
1.23457 deg
>>> round(q, 8)
1.23457 deg