Skip to main content
VKUMA.12
Associate III
October 3, 2022
Question

Float variable not working in stm32cube_ide.

  • October 3, 2022
  • 4 replies
  • 2526 views

Hi,

Float type variable is not working in stm32cube_ide.

float r = 3.14;

when I debug the value of r it shows 3 and also I cross verify by using if condition.

if(r==3.14)

but condition fails, that means float variable not working in ide.

Please help!

This topic has been closed for replies.

4 replies

AScha.3
Super User
October 3, 2022

your joking, eh ?

write:->

float r = 3.1415f; // xxxf = float define

and bool compare == never useful working on float !! (or random, depends on compiler etc.)

"If you feel a post has answered your question, please click ""Accept as Solution""."
Tesla DeLorean
Guru
October 3, 2022

How are you debug/inspecting it?

3.14f would be the preferred usage.

Check printf() of floats is enabled, by default it might use the smaller library.​

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
LCE
Principal II
October 3, 2022

Check your project settings:

properties -> C/C++ Build -> Settings -> MCU Settings

There you can find settings about floating point hardware / software

and floating point support for printf.

VKUMA.12
VKUMA.12Author
Associate III
October 3, 2022

Thanks!

3.14f working fine.