Here you can find the source of roundedNumber(double inVal)
Parameter | Description |
---|---|
inVal | value to format |
public static String roundedNumber(double inVal)
//package com.java2s; //License from project: Open Source License import java.text.NumberFormat; public class Main { /** Flexible number formatter with different decimal places */ private static final NumberFormat FORMAT_FLEX = NumberFormat.getNumberInstance(); /**/*from ww w .ja v a2 s . c o m*/ * Format a number to a sensible precision * @param inVal value to format * @return formatted String using local format */ public static String roundedNumber(double inVal) { // Set precision of formatter int numDigits = 0; if (inVal < 1.0) numDigits = 3; else if (inVal < 10.0) numDigits = 2; else if (inVal < 100.0) numDigits = 1; // set formatter FORMAT_FLEX.setMaximumFractionDigits(numDigits); FORMAT_FLEX.setMinimumFractionDigits(numDigits); return FORMAT_FLEX.format(inVal); } }