{"id":297,"date":"2012-01-12T14:58:48","date_gmt":"2012-01-12T13:58:48","guid":{"rendered":"http:\/\/dev.flauschig.ch\/wordpress\/?p=297"},"modified":"2012-01-12T14:58:48","modified_gmt":"2012-01-12T13:58:48","slug":"pretty-format-file-size","status":"publish","type":"post","link":"http:\/\/dev.flauschig.ch\/wordpress\/?p=297","title":{"rendered":"Pretty Format File Size"},"content":{"rendered":"<pre class=\"brush: csharp; gutter: false; title: ; wrap-lines: false; notranslate\" title=\"\">\r\nstatic string FormatBytes(long bytes)\r\n{\r\n\tconst int scale = 1024;\r\n\tstring&#x5B;] orders = new string&#x5B;] { &quot;GB&quot;, &quot;MB&quot;, &quot;KB&quot;, &quot;Bytes&quot; };\r\n\tlong max = (long)Math.Pow(scale, orders.Length - 1);\r\n\r\n\tforeach (string order in orders)\r\n\t{\r\n\t\tif (bytes &gt; max)\r\n\t\t\treturn string.Format(&quot;{0:##.##} {1}&quot;, decimal.Divide(bytes, max), order);\r\n\r\n\t\tmax \/= scale;\r\n\t}\r\n\treturn &quot;0 Bytes&quot;;\r\n}\r\n<\/pre>\n<p>Source: <a href=\"http:\/\/sharpertutorials.com\/pretty-format-bytes-kb-mb-gb\/\">http:\/\/sharpertutorials.com\/pretty-format-bytes-kb-mb-gb\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>static string FormatBytes(long bytes) { const int scale = 1024; string&#x5B;] orders = new string&#x5B;] { &quot;GB&quot;, &quot;MB&quot;, &quot;KB&quot;, &quot;Bytes&quot; }; long max = (long)Math.Pow(scale, orders.Length &#8211; 1); foreach (string order in orders) { if (bytes &gt; max) return string.Format(&quot;{0:##.##} {1}&quot;, decimal.Divide(bytes, max), order); max \/= scale; } return &quot;0 Bytes&quot;; } Source: http:\/\/sharpertutorials.com\/pretty-format-bytes-kb-mb-gb\/<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[4,3],"tags":[],"class_list":{"0":"entry","1":"post","2":"publish","3":"author-roemer","4":"post-297","6":"format-standard","7":"category-csharp","8":"category-programming"},"acf":[],"views":1574,"_links":{"self":[{"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/297"}],"collection":[{"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=297"}],"version-history":[{"count":0,"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/297\/revisions"}],"wp:attachment":[{"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=297"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=297"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=297"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}