Java Number Format Pattern format(String value)

Here you can find the source of format(String value)

Description

Format only six decimal digits after decimal point.

License

Open Source License

Parameter

Parameter Description
value unformatted value

Return

formatted string

Declaration

static protected String format(String value) 

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 .ja v  a 2s . co  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(Number value)
  2. format(Number value)
  3. format(Object num, int dev, String valueIfZero)
  4. format(Object price)
  5. format(String str_number, int digits)
  6. formatAmtByComma(String amt, int len)
  7. formatBigNumber(long value)
  8. formatBitRate(long bytes)
  9. formatBytes(long bytes)