<?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: C Tutorial &#8211; printf, Format Specifiers, Format Conversions and Formatted Output</title>
	<atom:link href="http://www.codingunit.com/printf-format-specifiers-format-conversions-and-formatted-output/feed" rel="self" type="application/rss+xml" />
	<link>http://www.codingunit.com/printf-format-specifiers-format-conversions-and-formatted-output</link>
	<description>CodingUnit is your online resource for learning to program. Tutorials on C, C++, PHP, Python, MySQL, Java, JQuery, Opengl, DirectX and much more!</description>
	<lastBuildDate>Sat, 25 May 2013 13:17:59 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
	<item>
		<title>By: weethomas</title>
		<link>http://www.codingunit.com/printf-format-specifiers-format-conversions-and-formatted-output/comment-page-3#comment-6891</link>
		<dc:creator>weethomas</dc:creator>
		<pubDate>Tue, 21 May 2013 20:09:52 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=207#comment-6891</guid>
		<description><![CDATA[@Steve,

I hope you realize that unless your GPS is accurate to 3 meters, you are not going to actually have 3 meters of accuracy, regardless of how many decimal points it reports.

Regarding your storage issue. Single precision floats have at most 6 to 9 decimal digits of precision. When converting to a string, you are essentially generating a decimal representation of that float. This means that you are guaranteed that a number with 6 decimal digits can be converted back and forth between a float and it&#039;s string representation (which is decimal). However, any more than that really depends on the number (ie some 7, 8, and 9 digit decimals can be converted exactly while others won&#039;t).

So, in your case, you have an 8 digit decimal number that you first convert to float, then back to decimal (in string form). You should expect that at most, the first 6 digits will match. 

In you second example, you used atoi which converts an ascii string to an integer. Integers are whole numbers. They don&#039;t have decimal points. So, the output is exactly what you should have gotten. Try atof.]]></description>
		<content:encoded><![CDATA[<p>@Steve,</p>
<p>I hope you realize that unless your GPS is accurate to 3 meters, you are not going to actually have 3 meters of accuracy, regardless of how many decimal points it reports.</p>
<p>Regarding your storage issue. Single precision floats have at most 6 to 9 decimal digits of precision. When converting to a string, you are essentially generating a decimal representation of that float. This means that you are guaranteed that a number with 6 decimal digits can be converted back and forth between a float and it&#8217;s string representation (which is decimal). However, any more than that really depends on the number (ie some 7, 8, and 9 digit decimals can be converted exactly while others won&#8217;t).</p>
<p>So, in your case, you have an 8 digit decimal number that you first convert to float, then back to decimal (in string form). You should expect that at most, the first 6 digits will match. </p>
<p>In you second example, you used atoi which converts an ascii string to an integer. Integers are whole numbers. They don&#8217;t have decimal points. So, the output is exactly what you should have gotten. Try atof.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Amy</title>
		<link>http://www.codingunit.com/printf-format-specifiers-format-conversions-and-formatted-output/comment-page-3#comment-6726</link>
		<dc:creator>Amy</dc:creator>
		<pubDate>Mon, 15 Apr 2013 15:52:07 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=207#comment-6726</guid>
		<description><![CDATA[I need to print something in the format 0.144231E-03 or 0.88913E+03 etc so 0.number with scientific notation. 

Any ideas? Normal scientific notation (e.g. 5.1498587E+03 or 1.2039404-03 etc is no good, I can&#039;t use if for what I need to do)]]></description>
		<content:encoded><![CDATA[<p>I need to print something in the format 0.144231E-03 or 0.88913E+03 etc so 0.number with scientific notation. </p>
<p>Any ideas? Normal scientific notation (e.g. 5.1498587E+03 or 1.2039404-03 etc is no good, I can&#8217;t use if for what I need to do)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://www.codingunit.com/printf-format-specifiers-format-conversions-and-formatted-output/comment-page-3#comment-6724</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Sun, 14 Apr 2013 09:23:53 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=207#comment-6724</guid>
		<description><![CDATA[I need to print out a float containing a GPS coordinate in decimal values, which is -3.6 (ie: -123.123456)
The last digit(6) is critical since I am measuring down to within 3 meters, and require accurate logging and terminal data parsing.

Is there any way to print the value as well as parsing the float into a string while keeping the precision?

	float f2= -80.123456;
	sprintf(op, &quot;string %3.6f&quot;, f2);
	printf(op);

returns:   string -80.123459

--  OR  --

Is there another way I can parse the value from a string to a decimal and keep the precision?

	char read[10] = &quot;-80.123456&quot;;
	float lon = (1000000 * (float)atoi(read));
	printf(&quot;lf %3.6f\n&quot;, lon);

returns:  lf -80000000.000000

I am willing to split the char value into 3 integers, (high=&quot;-80&quot;, mid=&quot;123&quot;, low=&quot;456&quot;) but not sure how to parse it in to parts while maintaining precision. (value range &quot;123.123456&quot; to &quot;-101.123456&quot; read as a string)]]></description>
		<content:encoded><![CDATA[<p>I need to print out a float containing a GPS coordinate in decimal values, which is -3.6 (ie: -123.123456)<br />
The last digit(6) is critical since I am measuring down to within 3 meters, and require accurate logging and terminal data parsing.</p>
<p>Is there any way to print the value as well as parsing the float into a string while keeping the precision?</p>
<p>	float f2= -80.123456;<br />
	sprintf(op, &#8220;string %3.6f&#8221;, f2);<br />
	printf(op);</p>
<p>returns:   string -80.123459</p>
<p>&#8211;  OR  &#8211;</p>
<p>Is there another way I can parse the value from a string to a decimal and keep the precision?</p>
<p>	char read[10] = &#8220;-80.123456&#8243;;<br />
	float lon = (1000000 * (float)atoi(read));<br />
	printf(&#8220;lf %3.6f\n&#8221;, lon);</p>
<p>returns:  lf -80000000.000000</p>
<p>I am willing to split the char value into 3 integers, (high=&#8221;-80&#8243;, mid=&#8221;123&#8243;, low=&#8221;456&#8243;) but not sure how to parse it in to parts while maintaining precision. (value range &#8220;123.123456&#8243; to &#8220;-101.123456&#8243; read as a string)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sadam Hussain</title>
		<link>http://www.codingunit.com/printf-format-specifiers-format-conversions-and-formatted-output/comment-page-3#comment-6689</link>
		<dc:creator>Sadam Hussain</dc:creator>
		<pubDate>Mon, 08 Apr 2013 13:36:57 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=207#comment-6689</guid>
		<description><![CDATA[This is very helpful... I like it very much, I hope this will be benificial for everyone..........]]></description>
		<content:encoded><![CDATA[<p>This is very helpful&#8230; I like it very much, I hope this will be benificial for everyone&#8230;&#8230;&#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: neeraj</title>
		<link>http://www.codingunit.com/printf-format-specifiers-format-conversions-and-formatted-output/comment-page-3#comment-6687</link>
		<dc:creator>neeraj</dc:creator>
		<pubDate>Mon, 08 Apr 2013 12:23:13 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=207#comment-6687</guid>
		<description><![CDATA[its gud...]]></description>
		<content:encoded><![CDATA[<p>its gud&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ayesha</title>
		<link>http://www.codingunit.com/printf-format-specifiers-format-conversions-and-formatted-output/comment-page-3#comment-6670</link>
		<dc:creator>Ayesha</dc:creator>
		<pubDate>Mon, 01 Apr 2013 18:54:07 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=207#comment-6670</guid>
		<description><![CDATA[relli gud tutorial... thnx a lot..]]></description>
		<content:encoded><![CDATA[<p>relli gud tutorial&#8230; thnx a lot..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tutorial Pinguino &#8211; Capitulo 7. USB-CDC Emulación de Puerto Serie &#124; Blog MicroEmbebidos (PIC,MSP430,LPC,RTOS)</title>
		<link>http://www.codingunit.com/printf-format-specifiers-format-conversions-and-formatted-output/comment-page-3#comment-6665</link>
		<dc:creator>Tutorial Pinguino &#8211; Capitulo 7. USB-CDC Emulación de Puerto Serie &#124; Blog MicroEmbebidos (PIC,MSP430,LPC,RTOS)</dc:creator>
		<pubDate>Sun, 31 Mar 2013 17:42:11 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=207#comment-6665</guid>
		<description><![CDATA[[...] este enlace pueden encontrar diversos ejemplos con el printf para conocer como formatear variables y las prueben [...]]]></description>
		<content:encoded><![CDATA[<p>[...] este enlace pueden encontrar diversos ejemplos con el printf para conocer como formatear variables y las prueben [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Printf Formats &#124; Code Thrower</title>
		<link>http://www.codingunit.com/printf-format-specifiers-format-conversions-and-formatted-output/comment-page-3#comment-6482</link>
		<dc:creator>Printf Formats &#124; Code Thrower</dc:creator>
		<pubDate>Sun, 10 Feb 2013 03:53:54 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=207#comment-6482</guid>
		<description><![CDATA[[...] In C, printf is a powerful function with many formats. I found a very good tutorial here. [...]]]></description>
		<content:encoded><![CDATA[<p>[...] In C, printf is a powerful function with many formats. I found a very good tutorial here. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Subbu</title>
		<link>http://www.codingunit.com/printf-format-specifiers-format-conversions-and-formatted-output/comment-page-3#comment-6191</link>
		<dc:creator>Subbu</dc:creator>
		<pubDate>Fri, 18 Jan 2013 11:56:04 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=207#comment-6191</guid>
		<description><![CDATA[Crisp &amp; Clear explanation..!! Thanxx]]></description>
		<content:encoded><![CDATA[<p>Crisp &amp; Clear explanation..!! Thanxx</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jason</title>
		<link>http://www.codingunit.com/printf-format-specifiers-format-conversions-and-formatted-output/comment-page-3#comment-5976</link>
		<dc:creator>jason</dc:creator>
		<pubDate>Wed, 09 Jan 2013 04:14:46 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=207#comment-5976</guid>
		<description><![CDATA[very useful, concise and complete!]]></description>
		<content:encoded><![CDATA[<p>very useful, concise and complete!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
