Java Fraction Format formatDecNumber(Double number, String pattern)

Here you can find the source of formatDecNumber(Double number, String pattern)

Description

format Dec Number

License

Open Source License

Declaration

public static final String formatDecNumber(Double number, String pattern) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.text.DecimalFormat;

public class Main {
    public static final String NUMBER_PATTERN_1 = "####.0000";

    public static final String formatDecNumber(Double number, String pattern) {
        DecimalFormat decimalFormat = new DecimalFormat();
        decimalFormat.setDecimalSeparatorAlwaysShown(false);
        if (number == null) {
            number = 0.0;/*from w  w  w  .j  a v a 2  s. c o m*/
        }
        if (pattern == null || "".equals(pattern)) {
            pattern = NUMBER_PATTERN_1;
        } else {
            decimalFormat.applyPattern(pattern);
        }
        return decimalFormat.format(number);
    }
}

Related

  1. formatDecimal(double value, int precision)
  2. formatDecimal(double value, String mask)
  3. formatDecimal(String format, double value)
  4. formatDecimals(double d, int mantissa)
  5. formatDecimals(double number)
  6. formatDegToDms(double degrees, double min, double max)
  7. formatDisplay(Double value)
  8. formatDistance(float distance)
  9. formatDollarAmount(float amount)