<?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>How to display float number in MCP App?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/14354/how-to-display-float-number-in-mcp-app</link><description>Hi there! 
 I want to send a float from nRF51822 to MCP App. I use this code: 
 float m_temperature = 26.3f;
uint8_array_t temperature_data_array;
temperature_data_array.p_data = (uint8_t*)(&amp;amp;m_temperature);
temperature_data_array.size = sizeof(m_temperature</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 08 Jun 2016 08:54:20 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/14354/how-to-display-float-number-in-mcp-app" /><item><title>RE: How to display float number in MCP App?</title><link>https://devzone.nordicsemi.com/thread/54808?ContentTypeID=1</link><pubDate>Wed, 08 Jun 2016 08:54:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:594858e7-88cb-4fd6-91eb-6b2d6e7073bd</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;I believe this is an issue regarding &lt;a href="https://en.wikipedia.org/wiki/Endianness"&gt;endianness&lt;/a&gt; and floating point formats. &lt;a href="https://www.bluetooth.com/specifications/assigned-numbers/format-types"&gt;Bluetooth&lt;/a&gt; and our SDKs are using the &lt;a href="https://www.google.no/webhp?sourceid=chrome-instant&amp;amp;ion=1&amp;amp;espv=2&amp;amp;ie=UTF-8#q=IEEE-11073"&gt;IEEE-11073 format&lt;/a&gt; while the app is using &lt;a href="https://en.wikipedia.org/wiki/IEEE_754-1985"&gt;IEEE-754 format&lt;/a&gt;. &lt;a href="https://www.bluetooth.org/DocMan/handlers/DownloadDoc.ashx?doc_id=272346"&gt;Here&lt;/a&gt; is an overveiw of what the IEEE-11073 is all about.&lt;/p&gt;
&lt;p&gt;IEEE-11073 standard (from PDF):&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/11073.PNG" alt="image description" /&gt;&lt;/p&gt;
&lt;p&gt;IEEE-754 standard:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/754.PNG" alt="image description" /&gt;&lt;/p&gt;
&lt;p&gt;The endianness issue is &lt;a href="https://devzone.nordicsemi.com/question/74988/help-why-is-the-output-is-different-than-input/"&gt;discussed here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;It seems like there is &lt;a href="https://devzone.nordicsemi.com/question/15124/how-do-i-send-an-unsigned-float-over-the-air-as-a-characteristic-value/"&gt;an easy fix&lt;/a&gt; on the Android side (I have not tried it), but it is not implemented in the app. If you look in the ble_app_hts example in the SDK you can see how the temperature value&amp;#39;s exponent and mantissa is stored in a struct:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;typedef struct
{
  int8_t  exponent;   /**&amp;lt; Base 10 exponent */
  int32_t mantissa;   /**&amp;lt; Mantissa, should be using only 24 bits */
} ieee_float32_t;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Before transmission the exponent and mantissa are encoded into a four bytes long buffer and the bytes are reversed (it happens in hts_measurement_encode() in the SDK example). Finally the float is treated as a 11073 format float on the other side.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>