Simple stringifying using << operator
I see a number of things that may help you improve your program.

Gather constants together

The relationship among the numerical values that determine which unit is used and the divisor and the actual unit name is contained within a single function, which is good, but it could be more clear if expressed as a structure.  For example, one could use this:

struct Units {
  int limit;
  double divisor;
  std::string name;
};
static const std::array&lt;Units,4&gt; units; 


Then outside of the class, we supply the values:

const std::array&lt;my_length::Units,4&gt; my_length::units = {{
  { 10, 1, "mm" },
  { 1000, 10, "cm" },
  { 1000000, 1000, "m" },
  { 0, 1000000, "km" },
}};


This brings things into much closer proximity so that it can be more easily seen and understood.  We can do a little better with C++17 by using std::string_view instead of std::string for the unit name.

Isolate concerns

It's usually better to have each function just do one thing.  So insted of deciding on units and also printing, I'd suggest splitting those into two, using a private member function:

const Units&amp; selectUnit() const {
  auto ret{units.cbegin()};
  if (fmt_auto) {
      while (ret-&gt;limit &amp;&amp; v &gt;= ret-&gt;limit) {
          ++ret; 
      }
  }
  return *ret;
}


Now the operator&lt;&lt; looks like this:

friend std::ostream &amp;operator&lt;&lt;(std::ostream &amp;out, const my_length &amp;l) {
  const Units u{l.selectUnit()};
  return out &lt;&lt; l.id &lt;&lt; "/" &lt;&lt; l.name &lt;&lt; " : " 
      &lt;&lt; l.v/u.divisor &lt;&lt; u.name;
}


Use standard algorithms

The test code starts with this:

std::vector&lt;my_length&gt; lengths;
my_length l{0, "a", 1};
lengths.push_back(l);
uint64_t val = 17;
for (int i=1; i&lt;10; i++) {
    my_length l{i, std::string(1, 'a'+i), val};
    lengths.push_back(l);
    val *= 10;
}


I'd suggest that one could use std::iota instead.  I'll leave it to you to create the details of that.

Reconsider the design

Once constructed, there is no capability to do anything with the my_length object except to print it.  If all that's needed is printing, then it may be better to use a freestanding function in a namespace instead of an object, as suggested in the comments.  If not, then it makes sense to provide those other operations within the class.