String(float floatValue, int numberOfDecimalPlaces) issue when -1.0 < floatValue < 1.0


Hello There,
I am using the function String(float floatValue, int numberOfDecimalPlaces) to write the text of a textEditor like this:

TextEditor gainDb_;
float gainDbVal_;
gainDb_.setText(String(gainDbVal_), 2);

it all works great except for when the absolute value of gainDbVal_ is smaller than one, at which point the generated string has many more decimal places. On the other hand, if I do it the classic way:

TextEditor gainDb_;
float gainDbVal_;
std::stringstream stream;
stream << std::fixed << std::setprecision(2) << gainDbVal_;
std::string s = stream.str();

everything goes as intended and I get two digits after the comma.

Is this an intended behaviour? Am I doing something wrong? Is there a solution to my problem?
Thank you very much


if that is copied from your code, then yes, you are doing something wrong. You are passing 2 as the second parameter to setText, not the second parameter to String.