<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>C# &#8211; Giovanni F. Mazzeo De Santolo</title>
	<atom:link href="https://desantolo.com/tag/c/feed/" rel="self" type="application/rss+xml" />
	<link>https://desantolo.com</link>
	<description>That italian IT guy</description>
	<lastBuildDate>Mon, 28 Mar 2011 16:51:07 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.3</generator>
<site xmlns="com-wordpress:feed-additions:1">123042357</site>	<item>
		<title>Quick C# Programming Notes on String Formatting</title>
		<link>https://desantolo.com/2011/03/quick-c-programming-notes-on-string-formatting/</link>
					<comments>https://desantolo.com/2011/03/quick-c-programming-notes-on-string-formatting/#respond</comments>
		
		<dc:creator><![CDATA[Giovanni]]></dc:creator>
		<pubDate>Mon, 28 Mar 2011 16:30:56 +0000</pubDate>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[programming]]></category>
		<guid isPermaLink="false">http://desantolo.com/?p=164</guid>

					<description><![CDATA[Here is a few examples on the different ways to format strings when outputting data to the user. Computers usually store numbers without formatting. Some of these notes will tell you the exact code you would need to make a &#8230; <a href="https://desantolo.com/2011/03/quick-c-programming-notes-on-string-formatting/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>Here is a few examples on the different ways to format strings when outputting data to the user. Computers usually store numbers without formatting.</p>
<p>Some of these notes will tell you the exact code you would need to make a computer&#8217;s &#8220;224&#8221; to be outputted as &#8220;$224&#8221; or &#8220;224 %&#8221;.</p>
<p><span id="more-164"></span></p>
<blockquote><p>using System;</p>
<p>class FormattingNumbers<br />
{<br />
static void Main()<br />
{<br />
decimal theDecNumber = 12345.678m; //the &#8220;m&#8221; creates a literal of type decimal from a double<br />
//Using the ToString Method<br />
//the number in the format string is the precision specifier<br />
Console.WriteLine(&#8220;No formatting: &#8221; + theDecNumber.ToString());<br />
Console.WriteLine(&#8220;Currency formatting: &#8221; + theDecNumber.ToString(&#8220;C&#8221;));<br />
Console.WriteLine(&#8220;Exponential formatting: &#8221; + theDecNumber.ToString(&#8220;E&#8221;));<br />
Console.WriteLine(&#8220;Fixed-point formatting: &#8221; + theDecNumber.ToString(&#8220;F2&#8221;));<br />
Console.WriteLine(&#8220;General formatting: &#8221; + theDecNumber.ToString(&#8220;G&#8221;));<br />
Console.WriteLine(&#8220;Number formatting to 2 decimal places: &#8221; + theDecNumber.ToString(&#8220;N2&#8221;));<br />
Console.WriteLine(&#8220;Number formatting to 3 decimal places: &#8221; + theDecNumber.ToString(&#8220;N3&#8221;));<br />
Console.WriteLine(&#8220;Number formatting to 4 decimal places: &#8221; + theDecNumber.ToString(&#8220;N4&#8221;));<br />
Console.WriteLine(&#8220;Percent formatting: &#8221; + theDecNumber.ToString(&#8220;P0&#8221;));</p>
<p>int theIntNumber = 123456;<br />
Console.WriteLine(&#8220;Hexidecimal formatting (for integers): {0} = {1}&#8221;, theIntNumber, theIntNumber.ToString(&#8220;X&#8221;));</p>
<p>double theDblNumber = 1234567890;<br />
Console.WriteLine(&#8220;Custom formatting: {0} to US telephone {1}&#8221;, theDblNumber, theDblNumber.ToString( &#8220;(###) ### &#8211; ####&#8221; ));</p>
<p>//Keep console open if not run through command prompt<br />
Console.Write(&#8220;\nPress Enter to Continue&#8221;);<br />
Console.ReadLine();<br />
}<br />
}</p></blockquote>
<p>John Sheehan has some very good tips and information on <a href="http://john-sheehan.com/blog/net-cheat-sheets/" target="_blank">his blog</a>. For archive purposes I have mirrored his .NET cheatsheet (<a href="http://desantolo.com/wp-content/uploads/2011/03/msnet-formatting-strings.pdf" target="_blank">download link here</a>). Hope this helps you.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://desantolo.com/2011/03/quick-c-programming-notes-on-string-formatting/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">164</post-id>	</item>
	</channel>
</rss>
