Floating point value

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Posting new questions will be temporarily unavailable from Dec 21 to Jan 5 due to a scheduled community upgrade.

Floating point value

2,640 Views
chetan98
Contributor II

I'm using Kw45 sdk example, for KW45 board I'd like to print the Floating point accelerometer values to the terminal using shell I also tried.

sprintf(str,"%f");

printf("%s",str);

IDE using MCU expresso 

But using printf or sprintf it is not printing even decimal value.

Thanks

Chetan

Labels (1)
0 Kudos
Reply
3 Replies

2,522 Views
chetan98
Contributor II

Hello Happy Diwali,

I am using Kw45 wireless uart and I want print value with 3 precision after point.

For eg 300.645 

Thanks 

Chetan 

0 Kudos
Reply

2,441 Views
sofiaurueta
NXP Employee
NXP Employee

Hello @chetan98 ,

 

Similarly to the ble_shell example, in the wireless_uart example, values are printed to the terminal using Serial_PrintDec function, which internally calls FORMAT_Dec2Str to convert integers into strings. See fsl_format.c for the conversion process:

 

/*Convert a uint32 to string*/

uint8_t *FORMAT_Dec2Str(uint32_t num)

 

Using this function as reference, you could implement a function to convert floating-point values to strings through a division-based method (split the float into its integer and decimal parts, convert each part to a string separately, and then combine them with a decimal point in between).

 

Best Regards,
Ana Sofia.

0 Kudos
Reply

2,611 Views
luis_maravilla
NXP Employee
NXP Employee

Hello Chetan,

Could you help us confirm what example are you using and for which SDK version please?

In the [ble_shell] example from the KW45 SDK, values are printed to the terminal using the function [SHELL_PrintfSynchronization], which is defined in [ble_shell.h].

To print integer values, the SDK uses [shell_writeDec], which internally calls [FORMAT_Dec2Str] to convert integers into strings. This conversion process is implemented in [fsl_format.c].

Using this approach as a reference, you could apply a similar method to convert floating-point values to strings and send to terminal.

 

Hope this information work for you.

Best Regards

Luis

0 Kudos
Reply