Java Fraction Format format(double num)

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

Description

format

License

Apache License

Declaration

public static String format(double num) 

Method Source Code


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

import java.text.DecimalFormat;

public class Main {

    public static String format(double num) {
        return new DecimalFormat(",###").format(num);
    }/*from w w  w .  jav  a2s.c  om*/

    public static String format(double num, int n) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            sb.append('0');
        }
        return new DecimalFormat("0." + sb.toString()).format(num);
    }
}

Related

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