Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

Smart Bluetooth Forum Discussions

Anonymous
Not applicable

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.

0 Likes
1 Solution
JacobT_81
Employee
Employee
250 likes received 100 likes received 50 likes received

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

View solution in original post

0 Likes
4 Replies
JacobT_81
Employee
Employee
250 likes received 100 likes received 50 likes received

Hi llynch

The 20736/37/s chip doesn't support floating point operations.

Jacob

0 Likes
Anonymous
Not applicable

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?

0 Likes

There is a good discussion on this topic here: Re: Floating-Point Arithmetic

0 Likes
JacobT_81
Employee
Employee
250 likes received 100 likes received 50 likes received

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

0 Likes