Round disk sizes
authorTom Hughes <tom@compton.nu>
Mon, 30 Nov 2015 14:43:38 +0000 (14:43 +0000)
committerTom Hughes <tom@compton.nu>
Mon, 30 Nov 2015 14:43:38 +0000 (14:43 +0000)
cookbooks/hardware/templates/default/ohai.rb.erb

index 2874f3d65898bf9371ad680f3afdb8792380267c..150efae45d8841d1ea1b938881b926decf35e855 100644 (file)
@@ -25,14 +25,17 @@ Ohai.plugin(:Hardware) do
     if kb == 0
       ""
     else
-      kblog10 = Math.log10(kb)
+      kblog10 = Math.log10(kb).floor
+
+      kb = kb.to_f * 2 / 10**kblog10
+      kb = kb.round.to_f / 2
 
       if kblog10 >= 9
-        format "%gTB", 10**(kblog10 - 9)
+        format "%gTB", kb * 10**(kblog10 - 9)
       elsif kblog10 >= 6
-        format "%dGB", 10**(kblog10 - 6)
+        format "%dGB", kb * 10**(kblog10 - 6)
       else
-        format "%dMB", 10**(kblog10 - 3)
+        format "%dMB", kb * 10**(kblog10 - 3)
       end
     end
   end