Here you can find the source of formatNumber(double number)
public static String formatNumber(double number)
//package com.java2s; /*//w w w . ja va 2 s.c o m * This file is part of Matter Overdrive * Copyright (c) 2015., Simeon Radivoev, All rights reserved. * * Matter Overdrive is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Matter Overdrive is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Matter Overdrive. If not, see <http://www.gnu.org/licenses>. */ import java.text.DecimalFormat; public class Main { public static String formatNumber(double number) { return formatNumber(number, "0.00"); } public static String formatNumber(double number, String decialFormat) { if (number > 1000000000000000D) { return new DecimalFormat(decialFormat + "Q") .format((number / 1000000000000000.00D)); } if (number > 1000000000000D) { return new DecimalFormat(decialFormat + "T") .format((number / 1000000000000.00D)); } else if (number > 1000000000D) { return new DecimalFormat(decialFormat + "B") .format((number / 1000000000.00D)); } else if (number > 1000000D) { return new DecimalFormat(decialFormat + "M") .format((number / 1000000.00D)); } else if (number > 1000D) { return new DecimalFormat(decialFormat + "K") .format((number / 1000.00D)); } else { return new DecimalFormat(decialFormat).format(number); } } }