Here you can find the source of format(Number number)
Parameter | Description |
---|---|
number | Number to convert to a string. |
public static String format(Number number)
//package com.java2s; /* ****************************************************************************** * Copyright (c) 2006-2013 XMind Ltd. and others. * * This file is a part of XMind 3. XMind releases 3 and * above are dual-licensed under the Eclipse Public License (EPL), * which is available at http://www.eclipse.org/legal/epl-v10.html * and the GNU Lesser General Public License (LGPL), * which is available at http://www.gnu.org/licenses/lgpl.html * See http://www.xmind.net/license.html for details. * * Contributors:// w w w.ja va 2 s .c o m * XMind Ltd. - initial API and implementation *******************************************************************************/ public class Main { /** * Returns a formatted string of the specified number. All trailing zeroes * or decimal points will be stripped. * * @param number * Number to convert to a string. * @return A formatted string. */ public static String format(Number number) { String formatted = Double.toString(number.doubleValue()).replaceAll("\\.0+$", "") //$NON-NLS-1$ //$NON-NLS-2$ .replaceAll("(\\.[0-9]*[1-9])0+$", "$1"); //$NON-NLS-1$ //$NON-NLS-2$ return formatted; } /** * Returns a formatted string of the specified object. * * @param number * Object to convert to a string. * @return A formatted string. */ public static String format(Object obj) { if (obj instanceof Number) { return format((Number) obj); } else { return obj.toString(); } } }