I would say the return type should be an Angle (or Bearing, ..). Create a class Angle to use. Internally it can use a floating point member for the decimal value. Then add a string formating member function to get the desired string when needed.
Advantages: Easy to perform calculations, and you can reduce the risk of mixing units, such as degrees and radians.
I use the following if it helps you in any way
class angle
{
public:
enum unit
{
rad = 0,
deg = 1
};
angle() : r(0.) {}
explicit angle(double a, unit u = rad) {
if (u == rad) r = a; else r = a*M_PI/180;
}
angle(const angle& fi) : r(fi.r) {}
double radians() const { return r; }
double degrees() const { return r*180/M_PI; }
void normalize() {
while(r<-M_PI)r+=2*M_PI;while(r>=M_PI)r-=2*M_PI;
}
void normalize_positive() {
while(r<0.)r+=2*M_PI;while(r>=2*M_PI)r-=2*M_PI;
}
angle& operator= (const angle &fi) { if (&fi != this) r = fi.r; return *this; }
angle& operator+= (const angle &fi) { r += fi.r; return *this; }
angle& operator-= (const angle &fi) { r -= fi.r; return *this; }
bool operator== (const angle &fi) { return r == fi.r; }
bool operator> (const angle &fi) { return r > fi.r; }
bool operator< (const angle &fi) { return r < fi.r; }
bool operator>= (const angle &fi) { return r >= fi.r; }
bool operator<= (const angle &fi) { return r <= fi.r; }
angle operator- () { return angle(-r); }
angle operator- (const angle& fi) { return angle(r-fi.r); }
protected:
double r;
};
You can easily add your formating functions to this class, or better yet, create a formating class that does the job on an angle instance.