List of usage examples for java.text NumberFormat setMinimumIntegerDigits
public void setMinimumIntegerDigits(int newValue)
From source file:org.easycloud.las.core.util.TimeUtil.java
/** * Calculate the elapsed time between two times specified in milliseconds. * * @param start The start of the time period * @param end The end of the time period * @return a string of the form "XhYmZs" when the elapsed time is X hours, Y minutes and Z seconds or null if start > end. *//*from ww w . ja v a 2s. c o m*/ public static String elapsedTime(long start, long end) { if (start > end) { return null; } long[] elapsedTime = new long[TIME_FACTOR.length]; for (int i = 0; i < TIME_FACTOR.length; i++) { elapsedTime[i] = start > end ? -1 : (end - start) / TIME_FACTOR[i]; start += TIME_FACTOR[i] * elapsedTime[i]; } NumberFormat nf = NumberFormat.getInstance(); nf.setMinimumIntegerDigits(2); StringBuffer buf = new StringBuffer(); for (int i = 0; i < elapsedTime.length; i++) { if (i > 0) { buf.append(":"); } buf.append(nf.format(elapsedTime[i])); } return buf.toString(); }
From source file:org.apache.camel.dataformat.bindy.BindyAbstractFactory.java
private static NumberFormat getNumberFormat() { // Get instance of NumberFormat NumberFormat nf = NumberFormat.getInstance(); // set max number of digits to 3 (thousands) nf.setMaximumIntegerDigits(3);/*from www. java 2 s. c o m*/ nf.setMinimumIntegerDigits(3); return nf; }
From source file:com.streamsets.datacollector.util.SystemProcessImpl.java
/** * @return a unique number which shorts in descending order *///from w ww. j a va2 s . c om private static String nextId() { NumberFormat numberFormat = NumberFormat.getInstance(); numberFormat.setMinimumIntegerDigits(10); numberFormat.setGroupingUsed(false); SimpleDateFormat dateFormat = new SimpleDateFormat("YYYY-MM-dd_HH.mm.ss"); return Utils.format("{}-{}", dateFormat.format(new Date()), numberFormat.format(fileCounter.incrementAndGet())); }
From source file:us.fatehi.pointlocation6709.format.PointLocationFormatter.java
private static NumberFormat getNumberFormat(final int integerDigits) { final NumberFormat numberFormat = NumberFormat.getInstance(); numberFormat.setMinimumIntegerDigits(integerDigits); numberFormat.setMinimumFractionDigits(5); numberFormat.setMaximumFractionDigits(5); numberFormat.setGroupingUsed(false); return numberFormat; }
From source file:us.fatehi.pointlocation6709.format.PointLocationFormatter.java
private static NumberFormat getIntegerFormat(final int integerDigits) { final NumberFormat numberFormat = NumberFormat.getIntegerInstance(); numberFormat.setMinimumIntegerDigits(integerDigits); return numberFormat; }
From source file:org.rhq.core.util.StringUtil.java
public static String formatDuration(long duration, int scale, boolean minDigits) { long hours;//from w ww. j ava 2 s . c om long mins; int digits; double millis; hours = duration / 3600000; duration -= hours * 3600000; mins = duration / 60000; duration -= mins * 60000; millis = (double) duration / 1000; StringBuilder buf = new StringBuilder(); if ((hours > 0) || (minDigits == false)) { buf.append(((hours < 10) && (minDigits == false)) ? ("0" + hours) : String.valueOf(hours)).append(':'); minDigits = false; } if ((mins > 0) || (minDigits == false)) { buf.append(((mins < 10) && (minDigits == false)) ? ("0" + mins) : String.valueOf(mins)).append(':'); minDigits = false; } // Format seconds and milliseconds NumberFormat fmt = NumberFormat.getInstance(); digits = (((minDigits == false) || ((scale == 0) && (millis >= 9.5))) ? 2 : 1); fmt.setMinimumIntegerDigits(digits); fmt.setMaximumIntegerDigits(2); // Max of 2 fmt.setMinimumFractionDigits(0); // Don't need any fmt.setMaximumFractionDigits(scale); buf.append(fmt.format(millis)); return buf.toString(); }
From source file:org.aspectj.testing.MakeTestClass.java
public void makeTestClass() throws Exception { FileOutputStream fos = new FileOutputStream(className + ".java"); PrintStream out = new PrintStream(fos); out.print(HEADER);//from www .j av a2 s . c o m out.print(className); out.print(BODY_1); out.print(className); out.print(BODY_2); out.print(suiteFile); out.print(BODY_3); out.println(); int testNo = 1; NumberFormat nf = NumberFormat.getInstance(); nf.setMinimumIntegerDigits(3); for (AjcTest test : tests) { out.println(); out.print(" public void test"); out.print(nf.format(testNo++)); out.println("(){"); out.println(" runTest(\"" + test.getTitle() + "\");"); out.println(" }"); } out.println(); out.println(FOOTER); out.close(); }
From source file:com.discursive.jccook.collections.bag.BagExample.java
private void printAlbums(Bag albumBag) { Set albums = albumBag.uniqueSet(); Iterator albumIterator = albums.iterator(); while (albumIterator.hasNext()) { Album album = (Album) albumIterator.next(); NumberFormat format = NumberFormat.getInstance(); format.setMinimumIntegerDigits(3); format.setMaximumFractionDigits(0); System.out.println("\t" + format.format(albumBag.getCount(album)) + " - " + album.getBand()); }/*from ww w. j av a2 s. c o m*/ }
From source file:org.efaps.ui.servlet.FileServlet.java
/** * @param _personId personid/*from w ww .j a va 2 s . c o m*/ * @param _fileName name of the file * @return the file if found * @throws IOException on error */ private File getFile(final Long _personId, final String _fileName) throws IOException { File tmpfld = AppConfigHandler.get().getTempFolder(); if (tmpfld == null) { final File temp = File.createTempFile("eFaps", ".tmp"); tmpfld = temp.getParentFile(); temp.delete(); } final File storeFolder = new File(tmpfld, FileServlet.TMPFOLDERNAME); final NumberFormat formater = NumberFormat.getInstance(); formater.setMinimumIntegerDigits(8); formater.setGroupingUsed(false); final File userFolder = new File(storeFolder, formater.format(_personId)); if (!userFolder.exists()) { userFolder.mkdirs(); } return new File(userFolder, _fileName); }
From source file:org.polymap.kaps.importer.test.NumberFormatterTest.java
public void testThousands() { NumberFormat nf = NumberFormat.getNumberInstance(Locale.getDefault()); nf.setMaximumIntegerDigits(10);//from w w w.ja v a2 s. com nf.setMaximumFractionDigits(10); nf.setMinimumIntegerDigits(10); nf.setMinimumFractionDigits(10); System.out.println(nf.format(12345)); }