<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Formatting File Sizes</title>
	<atom:link href="http://www.brianlow.com/index.php/2007/03/25/formatting-file-sizes/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.brianlow.com/index.php/2007/03/25/formatting-file-sizes/</link>
	<description>Software Development Notes</description>
	<lastBuildDate>Wed, 25 Aug 2010 14:26:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Greg</title>
		<link>http://www.brianlow.com/index.php/2007/03/25/formatting-file-sizes/comment-page-1/#comment-65</link>
		<dc:creator>Greg</dc:creator>
		<pubDate>Fri, 30 May 2008 20:05:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.brianlow.com/index.php/2007/03/25/formatting-file-sizes/#comment-65</guid>
		<description>This is really good.  Thank you!
I noticed PB/EB are not handled as in StrFormatByteSize().  I&#039;ve modified it a bit, and will attempt to paste it below:

public static string FileSizeToString(long fileSize)
{
	string[] units = { &quot;bytes&quot;, &quot;KB&quot;, &quot;MB&quot;, &quot;GB&quot;, &quot;TB&quot;, &quot;PB&quot;, &quot;EB&quot; };
	string[] formats = { &quot;{0:f0} {1}&quot;, &quot;{0:f1} {1}&quot;, &quot;{0:f2} {1}&quot; };

	double value = fileSize;

	int thousand = 1000;
	int kilobyte = 1024;

	int index = 0;
	int decimals = 0;

	if (value &gt;= kilobyte)
	{
		while (value &gt;= thousand)
		{
			value = Math.Floor(value) / kilobyte;
			index++;
		}

		if (value &lt; 10)
		{
			value = Math.Floor(value * 100) / 100;
			decimals = 2;
		}
		else if (value &lt; 100)
		{
			value = Math.Floor(value * 10) / 10;
			decimals = 1;
		}
		else
		{
			value = Math.Floor(value * 1) / 1;
			// precision = 0; // already zero
		}
	}

	return String.Format(formats[decimals], value, units[index]);
}</description>
		<content:encoded><![CDATA[<p>This is really good.  Thank you!<br />
I noticed PB/EB are not handled as in StrFormatByteSize().  I&#8217;ve modified it a bit, and will attempt to paste it below:</p>
<p>public static string FileSizeToString(long fileSize)<br />
{<br />
	string[] units = { &#8220;bytes&#8221;, &#8220;KB&#8221;, &#8220;MB&#8221;, &#8220;GB&#8221;, &#8220;TB&#8221;, &#8220;PB&#8221;, &#8220;EB&#8221; };<br />
	string[] formats = { &#8220;{0:f0} {1}&#8221;, &#8220;{0:f1} {1}&#8221;, &#8220;{0:f2} {1}&#8221; };</p>
<p>	double value = fileSize;</p>
<p>	int thousand = 1000;<br />
	int kilobyte = 1024;</p>
<p>	int index = 0;<br />
	int decimals = 0;</p>
<p>	if (value &gt;= kilobyte)<br />
	{<br />
		while (value &gt;= thousand)<br />
		{<br />
			value = Math.Floor(value) / kilobyte;<br />
			index++;<br />
		}</p>
<p>		if (value &lt; 10)<br />
		{<br />
			value = Math.Floor(value * 100) / 100;<br />
			decimals = 2;<br />
		}<br />
		else if (value &lt; 100)<br />
		{<br />
			value = Math.Floor(value * 10) / 10;<br />
			decimals = 1;<br />
		}<br />
		else<br />
		{<br />
			value = Math.Floor(value * 1) / 1;<br />
			// precision = 0; // already zero<br />
		}<br />
	}</p>
<p>	return String.Format(formats[decimals], value, units[index]);<br />
}</p>
]]></content:encoded>
	</item>
</channel>
</rss>
