"We use different formulas to find the distance of a segment on a number line, d=|a−b|" role="presentation" style="display: inline; font-size: 16px; position: relative;">d=|a−b|, and the distance of a segment in the coordinate plane, d=(x2−x1)2+(y2−y1)2" role="presentation" style="display: inline; font-size: 16px; position: relative;">d=(x2−x1)2+(y2−y1)2−−−−−−−−−−−−−−−−−−√. Why is it necessary to use the absolute value of the difference when finding the distance on a number line, but not necessary when finding the differences of the coordinates in the coordinate plane?"

values on the number line can be measured in either direction. So, it makes a difference which one is subtracted. The distance though, is always positive.

In the xy distance formula, the differences are squared, so that always gives a positive result.

If you think about it, the same formula would work on the number line.
d = √(x1-x2)^2
will always give a positive result.