Here you can find the source of formatNumber(Float d, int scalar)
public static String formatNumber(Float d, int scalar) throws Exception
//package com.java2s; /**/* w w w. j a v a 2 s .c om*/ * Copyright (C) 2002-2005 WUZEWEN. All rights reserved. * WUZEWEN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ import java.text.DecimalFormat; import java.text.NumberFormat; public class Main { public static String formatNumber(Double d, int scalar) throws Exception { double temp = d.doubleValue(); return formatNumber(temp, scalar); } public static String formatNumber(Float d, int scalar) throws Exception { float temp = d.floatValue(); return formatNumber(temp, scalar); } public static String formatNumber(double number, int scalar) throws Exception { String zero = "000000000000000000000000000000"; String format = "##0." + zero.substring(0, scalar); NumberFormat nf = new DecimalFormat(format); return nf.format(number); } public static String formatNumber(float number, int scalar) throws Exception { String zero = "000000000000000000000000000000"; String format = "##0." + zero.substring(0, scalar); NumberFormat nf = new DecimalFormat(format); return nf.format(number); } }