Java Fraction Format formatMetricsDecimal(double value)

Here you can find the source of formatMetricsDecimal(double value)

Description

format Metrics Decimal

License

Apache License

Declaration

public static String formatMetricsDecimal(double value) 

Method Source Code


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

import java.text.DecimalFormat;
import java.text.NumberFormat;

public class Main {
    public static final String NO_METRICS_LABEL = "-";

    public static String formatMetricsDecimal(double value) {
        //TODO: thread-safety of number format?
        //TODO: localisation?
        if (value == -1 || Double.isNaN(value) || Double.isInfinite(value)) {
            return NO_METRICS_LABEL;
        } else {//from  w ww .  j av  a2  s  .c o  m
            return getDecimalFormatter().format(value);
        }
    }

    private static NumberFormat getDecimalFormatter() {
        NumberFormat format = DecimalFormat.getNumberInstance();
        format.setMinimumFractionDigits(1);
        format.setMaximumFractionDigits(1);
        return format;
    }
}

Related

  1. formatInt(double value)
  2. formatIntoCurr(double num, int digits)
  3. formatIntRate(double rateInt)
  4. formatKnots(double v)
  5. formatManeyPattern(String pattern, Double amount)
  6. formatNoGrouping(double value)
  7. formatNormalDouble(double value)
  8. formatNum(double d)
  9. formatNum(double num, int numfracdigits)