 Mark as New
 Bookmark
 Subscribe
 Mute
 Subscribe to RSS Feed
 Permalink
 Report Inappropriate Content
Hello,
I am having some trouble with floating point numbers. I am using the lastest SDK.
I have a simply calculation:
int Data[]={0x1834}; //6196 in decimal
float factor=0.00698;
float result=0;
result=Data[0]*0.00698; //expected result would be 43.24808
printf("Result: %.2f",result); //print to two decimal places, 43.24
Every time I do this I get a round number to a whole number.
What is the correct way to print to two decimal places on this SDK?
Do I need to include some sort of header file to allow me to calculate floating point calculations?
Any examples would be great.
Thanks,
Luke.
Solved! Go to Solution.
 Labels:

BLE_PROFILE_CFG

Debug

Peripherhal UART

SDK 2.X
 Mark as New
 Bookmark
 Subscribe
 Mute
 Subscribe to RSS Feed
 Permalink
 Report Inappropriate Content
It's not a matter of importing libraries, the processor, architecturally, doesn't have the capability to deal with floating point vals.
Any decimals passed into an int will take on the value of the int chopped at the decimal point. Unless you're trying to do some heavy DSP, this shouldn't prove detrimental to work around.
Jacob
 Mark as New
 Bookmark
 Subscribe
 Mute
 Subscribe to RSS Feed
 Permalink
 Report Inappropriate Content
 Mark as New
 Bookmark
 Subscribe
 Mute
 Subscribe to RSS Feed
 Permalink
 Report Inappropriate Content
So I cant calculate a number that involves a decimal point?
Is there anyway of including a header file to allow the calculation?
It seems hard to believe that a cortex m3 based mcu cant calculate a floating point number?
 Mark as New
 Bookmark
 Subscribe
 Mute
 Subscribe to RSS Feed
 Permalink
 Report Inappropriate Content
There is a good discussion on this topic here: Re: FloatingPoint Arithmetic
 Mark as New
 Bookmark
 Subscribe
 Mute
 Subscribe to RSS Feed
 Permalink
 Report Inappropriate Content
It's not a matter of importing libraries, the processor, architecturally, doesn't have the capability to deal with floating point vals.
Any decimals passed into an int will take on the value of the int chopped at the decimal point. Unless you're trying to do some heavy DSP, this shouldn't prove detrimental to work around.
Jacob