-1

I want to convert a float value to the scientific value, what's the syntax in Arduino IDE? for example, float f = 0.0032 in float should be print like 3.2x10^(-3)

Serial.println(float2s(f, 7));

this syntax is not working in Arduino IDE.

Please help me to fix it.

Thanks in advance.

1 Answers1

0

I don't know what files you actually included in your program, but since you refer in general to the Arduino IDE I'll assume you didn't include anything manually (but the Arduino IDE included <Arduino.h> for you). In this case no function called float2s() was declared. The syntax is correct, you just need to write a char* float2s(float, unsigned int) function.
You can either write your own function or search for an implementation on the internet, e.g. here on the Arduino forum there is a working (although not ideal...) implementation of that function that would make Serial.println(float2s(f, 7)); work.

noearchimede
  • 188
  • 9
  • I’ve seen your code (which is posted in the wrong place, you should edit your question instead of adding an answer) and I think my answer still makes sense. You didn’t define any float2s function (neither could I find where you use it, maybe you removed it to make your code compile?) – noearchimede Mar 11 '18 at 09:22