Skip to content

Commit 084f57f

Browse files
JWock82JWock82
authored andcommitted
Updated comments
1 parent 3eb9dcb commit 084f57f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

ipycalc/calc.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,12 @@ def compute_value(expression, target_unit, target_precision):
274274
if target_unit != None:
275275
return str((eval(expression).to(target_unit)).magnitude) + '*' + target_unit
276276
elif target_precision != None:
277-
# Unitless values - convert to ensure proper cancellation
277+
# Unitless values - convert to ensure proper cancellation:
278+
# Unitless values require special consideration. Pint leaves values in terms of the
279+
# units used to calculate them. That means 60 ft / 12 in = 5 ft/in instead of 60.
280+
# As a workaround we'll convert that quantity to some units that cancel each other out.
281+
# In cases where there are no units (a pure float) we'll need to tag on some units
282+
# to make the `to` function available. These units should also cancel each other out.
278283
return str((eval(expression)*inch/inch).to(inch/inch))
279284
else:
280285
eval_result = eval(expression)

0 commit comments

Comments
 (0)