2026-04-02 5:34 AM - last edited on 2026-04-02 5:43 AM by Andrew Neil
To sum up my project, i get temperature value from NTC. I made ADC reading. There is no problem about getting values. I define temperature value as floating point variable. When observing it on debug screen, because it was floating, numbers after . is too much like seven digit. As you see in picture, is there any way to reduce the number of digits on debug window?
temperatureDisplay
Solved! Go to Solution.
2026-04-02 7:15 AM
@Ozone wrote:Not using float at all will save you several kB of code space.
Indeed.
Even though the F4 does have an FPU, it is only single-precision - which can cause issues with standard C libraries:
Be aware: Floating Point Operations on ARM Cortex-M4F
And that's apart from all the other issues inherent in floating-point on binary computers:
Pitfalls of Floating-Point Numbers (And How To Avoid Them)
What every computer scientist should know about floating-point arithmetic
See also: https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
2026-04-02 5:45 AM
@tensaisakuragi06 wrote:I define temperature value as floating point variable.
Why ?
2026-04-02 5:48 AM
Its a little disturbing. It feels like value changes frequently. I do not need precise measurement. Just two digits is enough for me. This is actually not a problem. I seek for if it was possible.
2026-04-02 6:17 AM
Instead of the variable itself, you can perhaps display an expression which contains rounded/truncated value.
Just an idea to be experimented with, maybe not viable - I don't use Cube.
JW
2026-04-02 6:18 AM
You can do the calculation in integer. Or in integer fractions ("scaled math", e.g. in 1/10th °C).
Not using float at all will save you several kB of code space.
I can't really comment on the CubeIDE debugger, I don't use it.
But I would check if the context menu has such a precision option, or check the manual.
2026-04-02 6:22 AM
In excell, it gives option show two digits after , :) . Its not a major problem(it is actually not a problem). Maybe later this option can be added. I am not sure this kind of thing is logical or not. By the way, when i display value on LCD or OLED(any kind of screen), i can display it as two digits after . as library functions allows me to do. So, if it is not possible i can left it as it is.
2026-04-02 7:15 AM
@Ozone wrote:Not using float at all will save you several kB of code space.
Indeed.
Even though the F4 does have an FPU, it is only single-precision - which can cause issues with standard C libraries:
Be aware: Floating Point Operations on ARM Cortex-M4F
And that's apart from all the other issues inherent in floating-point on binary computers:
Pitfalls of Floating-Point Numbers (And How To Avoid Them)
What every computer scientist should know about floating-point arithmetic
See also: https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
2026-04-02 7:22 AM
Be aware: Floating Point Operations on ARM Cortex-M4F this article give idea and helpful for me. I can accept it as solution. TY.
2026-04-02 7:32 AM - edited 2026-04-02 7:40 AM
You may want to scale to an integer. If you want 2 digits multiply by 100, if you want 3 multiply by 1000. etc. Add 0.5 to round.
You can also scale back to float/double, but the downside is that you cannot represent all decimal fractions perfectly with powers of 2. Such as 0.1:
If you want more options you can use snprintf to print the value to a string and then add the string to live expression.
2026-04-02 7:46 AM
@tensaisakuragi06 wrote:I can accept it as solution. TY.
It is a side-track from the original question of formatting in the debugger.
The thing with formatting in the debugger is - how much would it actually get used?
Remember that it's just a debug view - it's not an end-user display
As noted, a lot of embedded system just avoid floating-point altogether anyhow.