Java Fraction Format format(double value, double unit)

Here you can find the source of format(double value, double unit)

Description

format

License

Apache License

Declaration

public static String format(double value, double unit) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.text.DecimalFormat;

public class Main {
    public static String format(double value, String pattern) {
        return new DecimalFormat(pattern).format(value);
    }//from   w  w  w. j a v  a 2s .  c  o  m

    public static String format(double value, double unit) {
        int dotIndex = (unit + "").indexOf('.');
        if (dotIndex == -1) {
            return value + "";
        } else {
            int dotDigits = (unit + "").length() - dotIndex - 1;
            String pattern = "#.";
            for (int i = 0; i < dotDigits; i++) {
                pattern += "0";
            }
            return new DecimalFormat(pattern).format(value);
        }
    }
}

Related

  1. format(double value)
  2. format(double value)
  3. format(double value)
  4. format(double value)
  5. format(double value)
  6. format(double value, int decimalPlace)
  7. format(double value, String formatString)
  8. format(double x, int max, int min)
  9. format(final double d)