<?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>Martijn's C# Programming Blog &#187; integer</title>
	<atom:link href="http://www.dijksterhuis.org/tag/integer/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dijksterhuis.org</link>
	<description>Information, news about programming in C#</description>
	<lastBuildDate>Fri, 07 Aug 2009 21:26:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Converting C# strings to other types</title>
		<link>http://www.dijksterhuis.org/converting-strings-types/</link>
		<comments>http://www.dijksterhuis.org/converting-strings-types/#comments</comments>
		<pubDate>Tue, 03 Feb 2009 06:35:41 +0000</pubDate>
		<dc:creator>Martijn</dc:creator>
				<category><![CDATA[Beginner]]></category>
		<category><![CDATA[Learn C#]]></category>
		<category><![CDATA[converting]]></category>
		<category><![CDATA[float]]></category>
		<category><![CDATA[integer]]></category>
		<category><![CDATA[string]]></category>

		<guid isPermaLink="false">http://www.dijksterhuis.org/?p=532</guid>
		<description><![CDATA[If you are interested in turning a C# string into an integer, float, double or any other kind look no further. In todays post we make use of the convert and parse methods to convert strings into numbers. 
In C# the Convert class binds all the basic data types together. It is possible to convert [...]<p>This is a post from <a href="http://www.dijksterhuis.org">Martijn's C# Coding Blog</a>. </p>
]]></description>
			<content:encoded><![CDATA[<p><em>If you are interested in turning a C# string into an integer, float, double or any other kind look no further. In todays post we make use of the convert and parse methods to convert strings into numbers. </em><span id="more-532"></span></p>
<p>In C# the Convert class binds all the basic data types together. It is possible to convert (cast) to and from most data types by using this class. Be careful that you are likely to lose information if you are casting to a type that hold less information.</p>
<p><strong>Example 1: How to convert a C# string to an integer</strong></p>
<blockquote><p>string myString = &#8220;1024&#8243;;<br />
int myInteger = Convert.ToInt32(myString);
</p></blockquote>
<p><strong>Example 2: How to convert a C# integer to a strin</strong>g</p>
<blockquote><p>int myInteger = 1024;<br />
string myString = Convert.ToString(myInteger);</p></blockquote>
<p><strong>Example 3: How to convert a C# float/double to a string</strong></p>
<p>It is possible to directly convert a float to a string, but not the other way around. Note that floating point type values in C# are automatically a double unless you force the compiler (f) to turn them into a float. </p>
<blockquote><p>
float myFloat = 1000.245f; // We need an &#8220;f&#8221;<br />
string myString1 = Convert.ToString(myFloat);</p>
<p>double myDouble = 1000.245; // No need for an &#8220;f&#8221;<br />
string myString2 = Convert.ToString(myDouble);
</p></blockquote>
<p><strong>Example 4: How to convert a C# string to a float/double</strong></p>
<p>If you would like to convert a string to a float you will need to convert it to a double first, and then cast it down. A float contains only 32 bits of information, and is thus less precise than a double (which holds 64 bits).</p>
<blockquote><p>string myString = &#8220;1000.245&#8243;;<br />
double myDouble = Convert.ToDouble(myString);    // This is not a problem<br />
float myFloat = (float) Convert.ToDouble(myString);  // But we need to cast a float </p></blockquote>
<p>This is a post from <a href="http://www.dijksterhuis.org">Martijn's C# Coding Blog</a>. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.dijksterhuis.org/converting-strings-types/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
