Java Fraction Format format(double degrees)

Here you can find the source of format(double degrees)

Description

Remove decimal point from value and return its string representation

License

Open Source License

Parameter

Parameter Description
degrees a parameter

Return

formatted string

Declaration

static protected String format(double degrees) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://from w  w  w.j  a  v  a2 s .c  o m
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

import java.text.DecimalFormat;

public class Main {
    /**
     * Remove decimal point from value and return its string representation
     * 
     * @param degrees
     * 
     * @return formatted string
     */
    static protected String format(double degrees) {
        // String str = null;
        // String subStr = null;

        double dVal = degrees;
        // boolean negative = false;

        // Decimal format does the rounding for us.
        // if (dVal < -0.0000005) {
        // dVal -= 0.0000005;
        // } else if (dVal > 0.0000005) {
        // dVal += 0.0000005;
        // }

        // dVal *= 1000000.0;
        // int iVal = (int) dVal;
        // return ""+iVal;
        // str = Double.toString(dVal);
        // int dot = str.indexOf("."); //$NON-NLS-1$
        // subStr = str.substring(0, str.length() < dot + 7 ? str.length()
        // : dot + 7);
        // return subStr;
        DecimalFormat form = new DecimalFormat("###0.000000"); //$NON-NLS-1$
        return form.format(dVal);

    }

    /**
     * Format only six decimal digits after decimal point.
     * 
     * @param value
     *            unformatted value
     * 
     * @return formatted string
     */
    static protected String format(String value) {
        String subStr = null;

        int dot = value.indexOf("."); //$NON-NLS-1$
        subStr = value.substring(0, value.length() < dot + 7 ? value.length() : dot + 7);
        return subStr;

    }
}

Related

  1. format(double d)
  2. format(double d)
  3. format(double d, DecimalFormat unitFormatter)
  4. format(Double d, int digit)
  5. format(double d, java.text.NumberFormat format)
  6. format(double input, String format)
  7. format(double n)
  8. format(double no, String formatter)
  9. format(Double num)