Here you can find the source of toDegreesMinutes(double degrees, int nDecimals, boolean longitude)
public final static String toDegreesMinutes(double degrees, int nDecimals, boolean longitude)
//package com.java2s; import java.text.NumberFormat; public class Main { public static final String degreeSign = "\u00b0"; public static final String minuteSign = "'"; public final static String toDegreesMinutes(double degrees, int nDecimals, boolean longitude) { double[] dms = toDegreesMinutes(degrees); int deg = (int) dms[0]; double min = dms[1]; NumberFormat minutesFormatter = NumberFormat.getInstance(); minutesFormatter.setMinimumFractionDigits(nDecimals); minutesFormatter.setMaximumFractionDigits(nDecimals); minutesFormatter.setMinimumIntegerDigits(2); String hemisphere = longitude ? (degrees >= 0.0 ? "E" : "W") : (degrees >= 0.0 ? "N" : "S"); String degString = Integer.toString(Math.abs(deg)); String zeroes = "00".substring(0, (longitude ? 3 : 2) - degString.length()); degString = zeroes + degString;//from w ww .j av a2s.c o m return degString + degreeSign + minutesFormatter.format(min) + minuteSign + hemisphere; } public final static double[] toDegreesMinutes(double degrees) { double sign = (degrees >= 0.0) ? 1.0 : -1.0; degrees = Math.abs(degrees); double[] dms = new double[2]; dms[0] = Math.floor(degrees); double minutes = (degrees - dms[0]) * 60.0; dms[1] = minutes; dms[0] *= sign; return dms; } }