I can check if the value is really <1, and then find the leading zero and delete it. Not very elegant.
Agreed, but this is what you need to do without cheating in locales to define your own version of ostream :: operator <<(float). (You do not want this to be done this way.)
void float_without_leading_zero(float x, std::ostream &out) { std::ostringstream ss; ss.copyfmt(out); ss.width(0); ss << x; std::string s = ss.str(); if (s.size() > 1 && s[0] == '0') { s.erase(0); } out << s; }
source share