-__formatFunctions = {}
-getFormatFunction = (precision) ->
-  if precision is -1
-    identity
+significantDigitsBeforeDecimal = (value) -> 1 + Math.floor Math.log(value) / Math.LN10
+
+formatToSignificantDigits = (digits, value) ->
+  if value is 0
+    0
   else
-    __formatFunctions[precision] or __formatFunctions[precision] = d3.format ".#{precision}f"
+    sd = significantDigitsBeforeDecimal value
+    if sd >= digits
+      value.toFixed 0
+    else
+      magnitude = Math.pow 10, digits - sd
+      Math.round(value * magnitude) / magnitude
+
+formatReal = do ->
+  __formatFunctions = {}
+  getFormatFunction = (precision) ->
+    if precision is -1
+      identity
+    else
+      __formatFunctions[precision] or __formatFunctions[precision] = d3.format ".#{precision}f"
+
+  (precision, value) ->
+    (getFormatFunction precision) value
 
 Steam.FrameView = (_, _frame) ->
   createSummaryRow = (attribute, columns) ->

            '-'
          else
            if column.type is 'real'
              (getFormatFunction column.precision) value
            else
              value


    for attribute in attributes
      rows.push createSummaryRow attribute, columns
    rows

  createDataRows = (offset, rowCount, columns) ->
    rows = []
    for index in [0 ... rowCount]
