Adding comments and asserts.
[retire.git] / utils.py
index a9cd2f094d62b2ecd04a50630de762c24109860d..ce664204666e749bb1343fa86aa945a28004fbc5 100644 (file)
--- a/utils.py
+++ b/utils.py
@@ -1,13 +1,17 @@
 
 # Global helper functions
 def truncate(n, decimals=2):
+    """Truncate a float to a particular number of decimals."""
+    assert decimals > 0 and decimals < 10, "Decimals is weird"
     multiplier = 10 ** decimals
     return int(n * multiplier) / multiplier
 
 def format_money(number):
+    """Format a monetary amount with a $ and comma thousands separators."""
     return ("${:,}".format(truncate(number)))
 
 def format_rate(rate):
+    """Format a multiplier nee rate to look nice."""
     if rate >= 1.0:
         return format_rate(rate - 1.0)
     else: