Here you can find the source of degreesToString(final double value, final char positiveChar, final char negativeChar)
public static String degreesToString(final double value, final char positiveChar, final char negativeChar)
//package com.java2s; /*// w w w . j a va2 s .c om * Copyright 2007 Joachim Sauer * Copyright 2002-2006 Chriss Veness (vincenty formula in distance()) * * This file is part of bbTracker. * * bbTracker is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * bbTracker is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ public class Main { public static final char DEGREE = '\u00B0'; public static final char MINUTE = '\''; public static final char SECOND = '"'; public static String degreesToString(final double value, final char positiveChar, final char negativeChar) { if (Double.isNaN(value)) { return "-"; } char c; double d; if (value < 0) { d = -value; c = negativeChar; } else { d = value; c = positiveChar; } final StringBuffer buf = new StringBuffer(13); buf.append(c); final int degrees = (int) Math.floor(d); d = (d - degrees) * 60; final int minutes = (int) Math.floor(d); d = (d - minutes) * 60; final int seconds = (int) Math.floor(d); d = (d - seconds) * 100; final int hundrethSeconds = (int) Math.floor(d + 0.5d); appendTwoDigits(buf, degrees, ' ').append(DEGREE); appendTwoDigits(buf, minutes, ' ').append(MINUTE); appendTwoDigits(buf, seconds, ' ').append('.'); appendTwoDigits(buf, hundrethSeconds, '0').append(SECOND); return buf.toString(); } private static StringBuffer appendTwoDigits(final StringBuffer buf, final int value, final char c) { if (value < 10) { buf.append(c); } buf.append(value); return buf; } }