# float to string conversion broken?

**URL:** <https://community.sparkfun.com/t/float-to-string-conversion-broken/44755>\
**Category:** Artemis\
**Created:** [November 21, 2022, 2:08am UTC](https://community.sparkfun.com/t/float-to-string-conversion-broken/44755 "2022-11-21T02:08:52Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![rsalasidis](https://avatars.discourse-cdn.com/v4/letter/r/b19c9b/32.png) [@rsalasidis](https://community.sparkfun.com/u/rsalasidis)\
**Post date:** [November 21, 2022, 2:08am UTC](https://community.sparkfun.com/t/float-to-string-conversion-broken/44755/1 "2022-11-21T02:08:52Z")

</div>

I tried the following program

```auto
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);

  Serial.println("Test Ser Out");

  String test = String(5.02131234, 4);

  Serial.println(test);
}

void loop() {
  // put your main code here, to run repeatedly:
}

```

I get the following output

```auto
Test Ser Out
%6.4f

```

Any ideas

---

<div class="post-metadata">

**Author:** ![paulvha](https://avatars.discourse-cdn.com/v4/letter/p/65b543/32.png) [@paulvha](https://community.sparkfun.com/u/paulvha)\
**Post date:** [November 21, 2022, 7:53am UTC](https://community.sparkfun.com/t/float-to-string-conversion-broken/44755/2 "2022-11-21T07:53:11Z")

</div>

known issue. see [https://github.com/sparkfun/Arduino\_Apollo3/issues/278](https://github.com/sparkfun/Arduino_Apollo3/issues/278)

---

<div class="post-metadata">

**Author:** ![rsalasidis](https://avatars.discourse-cdn.com/v4/letter/r/b19c9b/32.png) [@rsalasidis](https://community.sparkfun.com/u/rsalasidis)\
**Post date:** [November 21, 2022, 5:20pm UTC](https://community.sparkfun.com/t/float-to-string-conversion-broken/44755/3 "2022-11-21T17:20:01Z")

</div>

Thanks, I see that after posting.

However, I do need to fix it, are there any precompiled mbed os files that can be used in place of the default one, or is there a detailed explanation how to resolve this using a windows (not linux) system.

I would rather avoid having to use a custom ftoa subroutine to do this.

Unfortunately as well, the project is very time limited, and this needs to be resolved over the next 24-48h.

Thanks

---

<div class="post-metadata">

**Author:** ![paulvha](https://avatars.discourse-cdn.com/v4/letter/p/65b543/32.png) [@paulvha](https://community.sparkfun.com/u/paulvha)\
**Post date:** [November 21, 2022, 6:47pm UTC](https://community.sparkfun.com/t/float-to-string-conversion-broken/44755/4 "2022-11-21T18:47:52Z")

</div>

There has not been an updated pre-compiled boards library.

You can use the same steps as I posted there on 7 april.

Unzip and make the 2 changes in HardwareSerial.cpp in the directory location: \AppData\Local\Arduino15\packages\Sparkfun\hardware\apollo3\2.2.1\cores\arduino\mbed-bridge\core-implement

---

<div class="post-metadata">

**Author:** ![rsalasidis](https://avatars.discourse-cdn.com/v4/letter/r/b19c9b/32.png) [@rsalasidis](https://community.sparkfun.com/u/rsalasidis)\
**Post date:** [November 21, 2022, 8:18pm UTC](https://community.sparkfun.com/t/float-to-string-conversion-broken/44755/5 "2022-11-21T20:18:42Z")

</div>

I did that, but it did not work. The program compiled ok, but the floats still only print the format string, and not the actual number.

I was not sure if that was for the padded strings, or if enables the standard printf.

I also tried adding an mbed\_app.json file in my root, but I don’t think that would work without an mbed recompile.

Let me know if the changes listed should work for enabling all std printd features, and maybe I did something wrong?

---

<div class="post-metadata">

**Author:** ![paulvha](https://avatars.discourse-cdn.com/v4/letter/p/65b543/32.png) [@paulvha](https://community.sparkfun.com/u/paulvha)\
**Post date:** [November 21, 2022, 8:55pm UTC](https://community.sparkfun.com/t/float-to-string-conversion-broken/44755/6 "2022-11-21T20:55:35Z")

</div>

you are right. The approach in the post is only changing/correcting a “serial.printf()”, not a sprintf(). need to take a bit more time to look into that.

---

<div class="post-metadata">

**Author:** ![rsalasidis](https://avatars.discourse-cdn.com/v4/letter/r/b19c9b/32.png) [@rsalasidis](https://community.sparkfun.com/u/rsalasidis)\
**Post date:** [November 21, 2022, 9:02pm UTC](https://community.sparkfun.com/t/float-to-string-conversion-broken/44755/7 "2022-11-21T21:02:31Z")

</div>

Ib can verify that serial.print(float var), does print correctly, not

sprint, or

Float various =:String(float,decpts)

---

<div class="post-metadata">

**Author:** ![jremington](https://yyz1.discourse-cdn.com/sparkfun/user_avatar/community.sparkfun.com/jremington/32/6595_2.png) [@jremington](https://community.sparkfun.com/u/jremington)\
**Post date:** [November 21, 2022, 11:30pm UTC](https://community.sparkfun.com/t/float-to-string-conversion-broken/44755/8 "2022-11-21T23:30:53Z")

</div>

You can always use dtostrf() to convert floats to C-strings (similar to the way you were trying to use sprintf()).

[https://www.hobbytronics.co.uk/arduino-float-vars](https://www.hobbytronics.co.uk/arduino-float-vars)

---

<div class="post-metadata">

**Author:** ![rsalasidis](https://avatars.discourse-cdn.com/v4/letter/r/b19c9b/32.png) [@rsalasidis](https://community.sparkfun.com/u/rsalasidis)\
**Post date:** [November 22, 2022, 2:25am UTC](https://community.sparkfun.com/t/float-to-string-conversion-broken/44755/9 "2022-11-22T02:25:03Z")

</div>

I used an ftoa function off the net for now (while hopefully a variant mbed OS is compiled with the full printf enabled). However, your suggestion would have made a good temporary replacement as well.

Thanks
