NumberFormat setMinimumFractionDigits - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for NumberFormat setMinimumFractionDigits method.

This code example shows how to use the following methods:format, setGroupingUsed, setMaximumFractionDigits, setMinimumFractionDigits, setMinimumIntegerDigits
import java.text.DecimalFormat; 
import java.text.NumberFormat; 
 
public class Format { 
	public static void main(String[] args){
		NumberFormat numForm = new DecimalFormat();
		numForm.setMinimumIntegerDigits(9);
		//Maximum also available for Integer digits and Fraction digits 
		numForm.setGroupingUsed(false);//stops it from inserting commas
		System.out.println(numForm.format(7.125));
		 
		//example of Fraction digit options 
		numForm.setMinimumIntegerDigits(5);
		numForm.setMinimumFractionDigits(5);
		System.out.println(numForm.format(7.125));
		numForm.setMinimumFractionDigits(0);
		numForm.setMaximumFractionDigits(2);
		System.out.println(numForm.format(7.125));
		System.out.println(numForm.format(7.135));//rounds to even
	} 

8
CodeRank
This code example shows how to use the following methods:setGroupingUsed, setMaximumFractionDigits, setMinimumFractionDigits, setMinimumIntegerDigits
This code example shows how to use the following methods:setGroupingUsed, setMaximumFractionDigits, setMinimumFractionDigits, setMinimumIntegerDigits
	private ITestSession session;
	private NumberFormat timeFormat;
 
	public TestSessionLabelProvider() { 
		timeFormat = NumberFormat.getNumberInstance();
		timeFormat.setGroupingUsed(true);
		timeFormat.setMinimumFractionDigits(3);
		timeFormat.setMaximumFractionDigits(3);
		timeFormat.setMinimumIntegerDigits(1);
	} 
	 
	public void setTestSession(ITestSession session) {
		this.session = session;		
	} 
	 
	public void update(ViewerCell cell) {
		Object element = cell.getElement();
		String mainText = getText(element);
		StyledString text = new StyledString(mainText);
		String elapsedTimeText = getElapsedTimeText(element);
6
CodeRank
This code example shows how to use the following methods:format, setMaximumFractionDigits, setMinimumFractionDigits, setMinimumIntegerDigits
			int halfHeight = gc.getFontMetrics().getHeight() / 2;
			gc.setForeground(fgColor);
			gc.setBackground(bgColor);
			int y = yAxis.calculatePixel(value);
			int fractionDigits = fractionDigits(yAxis.getRangeLow(), yAxis.getRangeHigh());
			nf.setMinimumFractionDigits(fractionDigits);
			nf.setMaximumFractionDigits(fractionDigits);
			nf.setMinimumIntegerDigits(integerDigits(yAxis.getRangeHigh()));
			gc.drawString(nf.format(value), xPixelHigh + labelLeftPadding, y - halfHeight);
		} 
	} 
 
	public int fractionDigits(double rangeLow, double rangeHigh) {
		return 2 + (int) (Math.ceil(-Math.log10(rangeHigh - rangeLow)));
	} 
	 
	public int integerDigits(double rangeHigh) {
		return (int) Math.log10(rangeHigh);
	} 
	 
6
CodeRank
This code example shows how to use the following methods:format, getMaximumFractionDigits, getMinimumFractionDigits, setMaximumFractionDigits, setMinimumFractionDigits
7
CodeRank
This code example shows how to use the following methods:setGroupingUsed, setMaximumFractionDigits, setMinimumFractionDigits
 
    private static final long serialVersionUID = -2555598825074884627L;
 
    private static NumberFormat COORD_FORMATTER = NumberFormat.getNumberInstance(Locale.ENGLISH);
    static { 
        COORD_FORMATTER.setMinimumFractionDigits(1);
        COORD_FORMATTER.setGroupingUsed(false);
        COORD_FORMATTER.setMaximumFractionDigits(16);
    } 
     
    private static Log log = LogFactory.getLog(org.geowebcache.grid.BoundingBox.class);
 
    private static String DELIMITER = ",";
 
    private static double EQUALITYTHRESHOLD = 0.03;
 
    public static final BoundingBox WORLD4326 = new BoundingBox(-180.0, -90.0, 180.0, 90.0);
 
    public static final BoundingBox WORLD3857 = new BoundingBox(-20037508.34, -20037508.34,
            20037508.34, 20037508.34); 
7
CodeRank
This code example shows how to use the following methods:setGroupingUsed, setMaximumFractionDigits, setMinimumFractionDigits, setMinimumIntegerDigits
		fTestRunnerPart= testRunnerPart;
		fLayoutMode= layoutMode;
		fShowTime= true;
 
		timeFormat= NumberFormat.getNumberInstance();
		timeFormat.setGroupingUsed(true);
		timeFormat.setMinimumFractionDigits(3);
		timeFormat.setMaximumFractionDigits(3);
		timeFormat.setMinimumIntegerDigits(1);
	} 
 
	public StyledString getStyledText(Object element) { 
		String label= getSimpleLabel(element);
		if (label == null) {
			return new StyledString(element.toString()); 
		} 
		StyledString text= new StyledString(label);
 
		ITestElement testElement= (ITestElement) element;
		if (fLayoutMode == TestRunnerViewPart.LAYOUT_HIERARCHICAL) {
6
CodeRank
This code example shows how to use the following methods:setGroupingUsed, setMaximumFractionDigits, setMinimumFractionDigits
public class MyStringToDoubleConverter extends StringToDoubleConverter { 
 
    @Override 
    protected NumberFormat getFormat(Locale locale) {
        NumberFormat format = super.getFormat(locale);
        format.setGroupingUsed(false);
        format.setMaximumFractionDigits(3);
        format.setMinimumFractionDigits(3);
        return format;
    } 
} 
6
CodeRank
This code example shows how to use the following methods:setMaximumFractionDigits, setMinimumFractionDigits
    private final String defaultCurrencyCode;
 
    static { 
        DEFAULT_NUMBER_FORMAT = NumberFormat.getNumberInstance();
        DEFAULT_CURRENCY_FORMAT = NumberFormat.getCurrencyInstance();
        DEFAULT_NUMBER_FORMAT.setMinimumFractionDigits(DEFAULT_CURRENCY_FORMAT.getMinimumFractionDigits());
        DEFAULT_NUMBER_FORMAT.setMaximumFractionDigits(DEFAULT_CURRENCY_FORMAT.getMaximumFractionDigits());
        LOCAL_CURRENCY_CODE = getDefaultCurrencyCode();
    } 
 
    static final boolean isAPropertyDefaultFacet() { 
        return PropertyDefaultFacet.class.isAssignableFrom(MoneyValueSemanticsProvider.class);
    } 
 
    private static String getDefaultCurrencyCode() {
        try { 
            return DEFAULT_CURRENCY_FORMAT.getCurrency().getCurrencyCode();
        } catch (final UnsupportedOperationException e) {
            return ""; 
        } 
6
CodeRank
This code example shows how to use the following methods:setMaximumFractionDigits, setMinimumFractionDigits
        this.hourFormatter = NumberFormat.getNumberInstance();
        this.hourSuffix = "h";
        this.minuteFormatter = NumberFormat.getNumberInstance();
        this.minuteSuffix = "m";
        this.secondFormatter = NumberFormat.getNumberInstance();
        this.secondFormatter.setMaximumFractionDigits(3);
        this.secondFormatter.setMinimumFractionDigits(3);
        this.secondSuffix = "s";
 
        // we don't use the calendar or numberFormat fields, but equals(Object) 
        // is failing without them being non-null 
        this.calendar = new GregorianCalendar();
        this.numberFormat = new DecimalFormat("0");
    } 
 
    /** 
     * Returns the base date/time used to calculate the elapsed time for 
     * display. 
     * 
     * @return The base date/time in milliseconds since 1-Jan-1970. 
6
CodeRank

Related NumberFormat setMinimumFractionDigits Questions & Answers:

setMinimumFractionDigits Method Overview
Sets the minimum number of digits allowed in the fraction portion of a number.
See Code Examples for other Java 8 NumberFormat Methods: