Here you can find the source of formatDecimalDisplay(final double _numberToFormat, final String _formatToApply)
Parameter | Description |
---|---|
_numberToFormat | The number to format with the _formatToApply. |
_formatToApply | The format to apply to the supplied number |
public static String formatDecimalDisplay(final double _numberToFormat, final String _formatToApply)
//package com.java2s; /*//from ww w. ja va2 s. c om * Created 2012 * * This file is part of Topological Data Analysis * edu.duke.math.tda * TDA is licensed from Duke University. * Copyright (c) 2012-2014 by John Harer * All rights reserved. * */ import java.util.*; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; public class Main { /** * Utility function for applying formatting to numbers. * @param _numberToFormat The number to format with the _formatToApply. * @param _formatToApply The format to apply to the supplied number * * @return The formatted number as a string. */ // 10/13/2005 hjs // Better (more robust) method for applying formatting to numbers public static String formatDecimalDisplay(final double _numberToFormat, final String _formatToApply) { String formattedNumber; // hjs 7/18/2007 When no number is passed in, or the format is invalid, // simply return the passed-in value (note: value can be NaN, which we can't format) // hjs 9/27/2007 Fix a localization issue (thanks to F. Menolascina and M. Clerx) try { DecimalFormat decimalFormatForDisplay = new DecimalFormat(_formatToApply, new DecimalFormatSymbols(Locale.US)); formattedNumber = decimalFormatForDisplay.format(_numberToFormat); } catch (Exception e) { // Simply use whatever number was supplied (including NaN, etc) formattedNumber = new Double(_numberToFormat).toString(); } return formattedNumber; } }