<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/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/"><channel><title>Using float variable</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/30474/using-float-variable</link><description> 
Hello everyone ! 

 
I have a problem with the float variables. 

 
For example, i define float a = 123456123456.1234 and char
lcd[30]; 

 
I used sprintf function to convert a to string and store into lcd
(sprintf(lcd,&amp;quot;%0.2f&amp;quot;,a);). 

 
Then, i export</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: Using float variable</title><link>https://community.arm.com/thread/137053?ContentTypeID=1</link><pubDate>Thu, 10 Oct 2013 06:34:39 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:b8574027-ed10-4973-9547-f909bfa23273</guid><dc:creator>&amp;#178;erik malund</dc:creator><description>&lt;p&gt;&lt;p&gt;
a lot of people &amp;#39;automatically&amp;#39; go for float when it is not neded.
Especially in small (e.g.&amp;#39;51) processors that is a BIG mistake. For a
&amp;#39;51 to process a float it need a LOT of cycles.&lt;/p&gt;

&lt;p&gt;
as an example: if all your values have up to two digits after the
decimal point process everything as 100 * actual value and just
insert the decinmal point in the appropiate place on the display&lt;/p&gt;

&lt;p&gt;
Erik&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using float variable</title><link>https://community.arm.com/thread/107334?ContentTypeID=1</link><pubDate>Wed, 09 Oct 2013 02:06:55 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:c84e297c-94e8-4029-a236-f19b7d364fbd</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
&amp;quot;do you have any solutions ?&amp;quot;&lt;/p&gt;

&lt;p&gt;
As I already suggested:&lt;br /&gt;
&amp;quot;If you want to play with lots of value digits, then you need to play
with some form of fixed-point arithmetic - and implement or use a
big-number library where the value is stored in an array of bytes or
integers.&amp;quot;&lt;/p&gt;

&lt;p&gt;
You did check the manual, to figure out the size for &amp;quot;float&amp;quot; and
&amp;quot;double&amp;quot; data types when using the C51 compiler?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using float variable</title><link>https://community.arm.com/thread/81495?ContentTypeID=1</link><pubDate>Tue, 08 Oct 2013 23:37:57 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:491342ff-c4cf-4007-94fe-d01c8da1d969</guid><dc:creator>king tran</dc:creator><description>&lt;p&gt;&lt;p&gt;
Thank for reply !&lt;/p&gt;

&lt;p&gt;
i&amp;#39;m tried with the double variable, but not success.&lt;/p&gt;

&lt;p&gt;
do you have any solutions ?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using float variable</title><link>https://community.arm.com/thread/68405?ContentTypeID=1</link><pubDate>Tue, 08 Oct 2013 22:33:58 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:25e09f9d-d8cc-4f83-99ba-e1fe5718fb85</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
Please take a closer look at the float data type.&lt;/p&gt;

&lt;p&gt;
If you have a signed 4-byte integer, the largest number you can
store is about 2.000.000.000, so about 9 value digits.&lt;/p&gt;

&lt;p&gt;
If you instead use the 4 bytes for a floating point value, where
some of the room is needed for mantissa and some for exponent, then
you aren&amp;#39;t likely to be able to store even more value digits than if
you fit an integer in that same storage space...&lt;/p&gt;

&lt;p&gt;
If you want to play with lots of value digits, then you need to
play with some form of fixed-point arithmetic - and implement or use
a big-number library where the value is stored in an array of bytes
or integers.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using float variable</title><link>https://community.arm.com/thread/62326?ContentTypeID=1</link><pubDate>Tue, 08 Oct 2013 22:19:33 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:0113adcc-e593-47ce-88e7-d86dbfa44621</guid><dc:creator>PinkyAndBrain JFK</dc:creator><description>&lt;p&gt;&lt;p&gt;
In the LCD result there are a lot &amp;quot;0&amp;quot; before the dot. May be
it&amp;acute;s a multiply failure in how the float is convertet into the
chars. Plus the number &amp;quot;123456123456.1234&amp;quot; don&amp;acute;t fit into 16
character, with the dot it consists of 17 characters.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using float variable</title><link>https://community.arm.com/thread/62328?ContentTypeID=1</link><pubDate>Tue, 08 Oct 2013 21:42:35 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:095afda5-09dc-40ec-8f48-dbc8d510bda3</guid><dc:creator>kashma Saltaman</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;And can everyone show me ...&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
Someone likely could, but everyone? My wife knows nothing about it
and cares even less.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>