Code Example: Convert Decimal Degrees and Minutes (DDM) to Decimal Degrees (DD)

How to convert between Decimal Degrees & Minutes (DDM) to Decimal Degrees (DD).

I always prefer to represent latitude and longitude as full decimal degrees (DD), I find it much simpler and you can do calculations with the values.  However, other people and devices love to use the slightly (to me) esoteric Decimal Degrees and Minutes (DDM) form and I have to remember how to convert to and from decimal degrees – so here’s a short description of how it’s done along with some C++ sample code.

Decimal Degrees: Latitude and longitude are just represented as a decimal degree value.

Decimal Degrees & Minutes: Encodes a whole number of degrees in the first few digits, the rest of the digits represent a decimal minutes value with 2 digits to the left of the decimal place representing a whole minute value,  e.g. 5254.9098940 : ddmm.mmmmmm

For example, a DDM value of: 5254.9098940 represents 52 degrees and 54.9098940 minutes.

To convert this to decimal degrees, we do something like this:

dd = 52 + (54.9098940 / 60) = 52.9151649 degrees.

And in code:

double ddm_to_dd(double ddm) {
    double degrees = floor(ddm / 100.0);
    double minutes = ddm - degrees * 100.0;
    double decimal_degrees = degrees + minutes / 60.0;
    return decimal_degrees;