 
   E.trade =
 
+    round: (value, digits) ->
+      magnitude = Math.pow(10, digits)
+      console.log value, magnitude, value * magnitude, Math.round(value * magnitude), (Math.round(value * magnitude) / magnitude), (Math.round(value * magnitude) / magnitude).toFixed(digits)
+      return (Math.round(value * magnitude) / magnitude).toFixed(digits)
+
     # Compute other amounts from unit pretax amount
     updateUnitPretaxAmount: (item) ->
       values = E.trade.itemValues(item)
       updates = {}
       # Compute pretax_amount
-      updates.pretax_amount = (values.unit_pretax_amount * values.quantity * (100.0 - values.reduction_percentage) / 100.0).toFixed(2)
+      updates.pretax_amount = values.unit_pretax_amount * values.quantity * (100.0 - values.reduction_percentage) / 100.0
       # Compute amount
-      updates.amount = (updates.pretax_amount * values.tax).toFixed(2)
+      updates.amount = E.trade.round(updates.pretax_amount * values.tax, 2)
+      # Round pretax amount
+      updates.pretax_amount = E.trade.round(updates.pretax_amount, 2)
       E.trade.itemValues(item, updates)
 
     # Compute other amounts from pretax amount

      values = E.trade.itemValues(item)
      updates = {}
      # Compute pretax_amount
      updates.pretax_amount = (-1 * values.unit_pretax_amount * values.credited_quantity * (100.0 - values.reduction_percentage) / 100.0).toFixed(2)
      # Compute unit_pretax_amount
      updates.amount = (updates.pretax_amount * values.tax).toFixed(2)
      E.trade.itemValues(item, updates)

    find: (item, name) ->

      values = E.trade.itemValues(item)
      updates = {}
      # Compute pretax_amount
      updates.pretax_amount = values.amount / values.tax
      # Compute unit_pretax_amount
      updates.unit_pretax_amount = E.trade.round(updates.pretax_amount / (values.quantity * (100.0 - values.reduction_percentage) / 100.0), 4)
      # Round pretax amount
      updates.pretax_amount = E.trade.round(updates.pretax_amount, 2)
      E.trade.itemValues(item, updates)

    # Compute other amounts from amount
