stmhal: fix single precision float printing error
Fixes #1435.
diff --git a/py/formatfloat.c b/py/formatfloat.c
index cc06361..a801055 100644
--- a/py/formatfloat.c
+++ b/py/formatfloat.c
@@ -142,7 +142,10 @@
char e_sign_char = '-';
if (num.f < 1.0F && num.f >= 0.9999995F) {
num.f = 1.0F;
- first_dig = '1';
+ if (e > 1) {
+ // numbers less than 1.0 start with 0.xxx
+ first_dig = '1';
+ }
if (e == 0) {
e_sign_char = '+';
}
diff --git a/tests/float/float_array.py b/tests/float/float_array.py
index c0f2c58..033877d 100644
--- a/tests/float/float_array.py
+++ b/tests/float/float_array.py
@@ -12,3 +12,5 @@
test(array('f'))
test(array('d'))
+
+print('{:.4f}'.format(array('f', b'\xcc\xcc\xcc=')[0]))