Here you can find the source of getValueFormatted(String name, String value)
Parameter | Description |
---|---|
name | Metric name |
value | Metric value |
public static String getValueFormatted(String name, String value)
//package com.java2s; /*//from w w w. j a v a2 s. c o m * This file is part of the MLDA. * * (c) Jose Maria Moyano Murillo * Eva Lucrecia Gibaja Galindo * Sebastian Ventura Soto <sventura@uco.es> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ import java.text.DecimalFormat; import java.text.NumberFormat; public class Main { /** * Get metric value formatted as String * * @param name Metric name * @param value Metric value * @return Formatted value */ public static String getValueFormatted(String name, String value) { String formattedValue; value = value.replace(",", "."); if (value.equals("-")) { return value; } if (value.equals("NaN")) { return "---"; } //Scientific notation numbers if ((((Math.abs(Double.parseDouble(value) * 1000) < 1.0)) && ((Math.abs(Double.parseDouble(value) * 1000) > 0.0))) || (Math.abs(Double.parseDouble(value) / 1000.0) > 10)) { NumberFormat formatter = new DecimalFormat("0.###E0"); formattedValue = formatter.format(Double.parseDouble(value)); } //Integer numbers else if ((name.toLowerCase().equals("attributes")) || (name.toLowerCase().equals("bound")) || (name.toLowerCase().equals("distinct labelsets")) || (name.toLowerCase().equals("instances")) || (name.toLowerCase().equals("labels x instances x features")) || (name.toLowerCase().equals("labels")) || (name.toLowerCase().equals("number of binary attributes")) || (name.toLowerCase().equals("number of labelsets up to 2 examples")) || (name.toLowerCase().equals("number of labelsets up to 5 examples")) || (name.toLowerCase().equals("number of labelsets up to 10 examples")) || (name.toLowerCase().equals("number of labelsets up to 50 examples")) || (name.toLowerCase().equals("number of nominal attributes")) || (name.toLowerCase().equals("number of numeric attributes")) || (name.toLowerCase().equals("number of unique labelsets")) || (name.toLowerCase() .equals("number of unconditionally dependent label pairs by chi-square test"))) { NumberFormat formatter = new DecimalFormat("#0"); formattedValue = formatter.format(Double.parseDouble(value)); } //Decimal numbers else { NumberFormat formatter = new DecimalFormat("#0.000"); formattedValue = formatter.format(Double.parseDouble(value)); } formattedValue = formattedValue.replace(",", "."); return formattedValue; } /** * Obtain metric value formatted to the specified number of decimal places * * @param value Metric value * @param nDecimals Number of decimal places * @return Formatted value */ public static String getValueFormatted(String value, int nDecimals) { String formattedValue; value = value.replace(",", "."); if (value.equals("-")) { return value; } if (value.equals("NaN")) { return "---"; } //Scientific notation numbers if ((((Math.abs(Double.parseDouble(value) * 1000) < 1.0)) && ((Math.abs(Double.parseDouble(value) * 1000) > 0.0))) || (Math.abs(Double.parseDouble(value) / 1000.0) > 10)) { NumberFormat formatter = new DecimalFormat("0.###E0"); formattedValue = formatter.format(Double.parseDouble(value)); } //Decimal numbers else { String f = "#0."; for (int i = 0; i < nDecimals; i++) { f += "0"; } NumberFormat formatter = new DecimalFormat(f); formattedValue = formatter.format(Double.parseDouble(value)); } formattedValue = formattedValue.replace(",", "."); return formattedValue; } }