<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>String to Float?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/6661/string-to-float</link><description>Is there a string to float function lurking somewhere in the libraries?
Thanks</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 23 Apr 2015 11:27:50 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/6661/string-to-float" /><item><title>RE: String to Float?</title><link>https://devzone.nordicsemi.com/thread/23366?ContentTypeID=1</link><pubDate>Thu, 23 Apr 2015 11:27:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6af65dec-ec90-4ca3-8e9e-e1ee340386cf</guid><dc:creator>the_purple_pig</dc:creator><description>&lt;p&gt;Thanks, this is very helpful - much appreciated.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: String to Float?</title><link>https://devzone.nordicsemi.com/thread/23365?ContentTypeID=1</link><pubDate>Thu, 23 Apr 2015 08:59:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:85c2ae6d-1de1-477a-a098-1971ff46b66b</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;Depends what you need to do with the data whether you need it to be a float at all. I assume that ddmm.mmmmm is degrees and decimal minutes to 5dp and also it could be dddmm.mmmmm for longitude. The resolution there is 1/100,000 th of a minute. 180 degrees is the max value which is 180 * 60 * 100000, 1 / 100000ths of a minute and that&amp;#39;s 1,080,000,000 which is 0x405f7e00 and fits happily inside an int32_t including the sign. So you could represent all the possible values from -180 to 180 degrees with a precision of 1/100,000th minute of arc in a 32bit integer.&lt;/p&gt;
&lt;p&gt;If whatever calculations you&amp;#39;re doing can be done in the unit &amp;quot;minutes / 100000&amp;quot;, then you can use integer arithmetic all the way through.&lt;/p&gt;
&lt;p&gt;And yes then parsing that string is something you could do with a short custom piece of code which requires no libraries and about 10 single-cycle multiplies only.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: String to Float?</title><link>https://devzone.nordicsemi.com/thread/23364?ContentTypeID=1</link><pubDate>Thu, 23 Apr 2015 08:02:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:28b59601-b8f1-4848-be40-54bf652cf856</guid><dc:creator>the_purple_pig</dc:creator><description>&lt;p&gt;Mmm OK. 143K flash and 6K ram is still a lot more than I am used to working with so I am not too worried about that. The speeed of conversion may be an issue.
The format of the string is always the same - GPS data (ddmm.mmmmm).
Maybe I can unpack the ddmm and mmmmm bits seperately into uints and ulongs then multiply/add into a float and then divide.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: String to Float?</title><link>https://devzone.nordicsemi.com/thread/23363?ContentTypeID=1</link><pubDate>Thu, 23 Apr 2015 00:56:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:871707d7-f6e3-44b0-85ce-605e9fde3d85</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;The usual atof(), strtof(), most of libc is available.&lt;/p&gt;
&lt;p&gt;You&amp;#39;re really converting strings to floats on a Cortex-M0 with very little memory and a 16MHz processor however? I try not even to use floating point on these chips if at all possible, it&amp;#39;s slow and thus power inefficient and bloats the code. atof() for instance is 300 bytes, strtof is 500 bytes. That&amp;#39;s running near 1% of your available flash with a softdevice, adds up quickly.&lt;/p&gt;
&lt;p&gt;Other options often include using scaled integers and converting things before you send them to the device, if whatever sending the value is more powerful.&lt;/p&gt;
&lt;p&gt;.. correcting the memory usage ..&lt;/p&gt;
&lt;p&gt;atof() itself is 300 bytes but also needs a other functions from the float/double/other libraries linked in. If you&amp;#39;re already doing some float arithmetic you may already have some of them linked, if you don&amp;#39;t the total code pulled in by one atof() from a base case with no other float requirements is 3Kb. strtof(), although that routine is larger at 500 bytes, requires a total of 2.4Kb of code to work.&lt;/p&gt;
&lt;p&gt;I didn&amp;#39;t measure how long it takes to do one conversion, I don&amp;#39;t think it&amp;#39;s terribly quick.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>