It seems once in a while someone asks about converting from degrees minutes seconds format to decimal or the other way around. 

I created a little procedure for just that purpose. 

restart; gc()

NULL

A little procedure to convert the form of degrees, minutes, seconds to decimal and vice versa.  

NULL

dms := proc (d, m := 0, s := 0) local con, d1, d2, d3; if 0 < frac(d) then d1 := floor(d); d2 := floor(60*frac(d)); d3 := 60*frac(60*frac(d)); con := cat(d1, `° `, d2, `' `, d3, `"`) else con := d+m/60.+s/3600. end if; print(con) end proc

NULL

Examples of use.

 

dms(45.2365)

`45° 14' 11.4000"`

(1)

dms(45, 14, 11.4)

45.23650000

(2)

NULL

Download dms.mw

edit - a quick realization is to remove the decimals that changes the fractions to floating decimals and change print(con) to print(evlaf(con)) to avoid rounding issues.


Please Wait...