List of usage examples for java.text NumberFormat setMinimumIntegerDigits
public void setMinimumIntegerDigits(int newValue)
From source file:NumFormat2.java
/** The main (and only) method in this class. */ public static void main(String[] av) { // Get a format instance NumberFormat form = NumberFormat.getInstance(); // Set it to look like 999.99[99] form.setMinimumIntegerDigits(3); form.setMinimumFractionDigits(2);//from w w w . j a v a 2 s .c om form.setMaximumFractionDigits(4); // Now print using it. for (int i = 0; i < data.length; i++) System.out.println(data[i] + "\tformats as " + form.format(data[i])); }
From source file:MainClass.java
public static void main(String[] av) { double data[] = { 0, 1, 22d / 7, 100.2345678 }; NumberFormat form = NumberFormat.getInstance(); // Set it to look like 999.99[99] form.setMinimumIntegerDigits(3); form.setMinimumFractionDigits(2);/*from www . j a va2s . c om*/ form.setMaximumFractionDigits(4); // Now print using it. for (int i = 0; i < data.length; i++) System.out.println(data[i] + "\tformats as " + form.format(data[i])); }
From source file:Main.java
public static void main(String[] args) throws Exception { NumberFormat numberFormat = NumberFormat.getNumberInstance(); numberFormat.setCurrency(Currency.getInstance(Locale.CANADA)); numberFormat.setMinimumIntegerDigits(2); }
From source file:Main.java
public static String getPageFileName(int p) { NumberFormat nf = NumberFormat.getInstance(Locale.US); nf.setMinimumIntegerDigits(3); return "page" + nf.format(p) + ".png"; }
From source file:Main.java
public static String numFormat(int len, int num) { NumberFormat formatter = NumberFormat.getNumberInstance(); formatter.setMinimumIntegerDigits(len); formatter.setGroupingUsed(false);/* ww w .ja va 2 s . co m*/ String numStr = formatter.format(num); return numStr; }
From source file:Main.java
public static String getTimeFromLong(long l) { Calendar c = Calendar.getInstance(); c.setTimeInMillis(l);// ww w . j a va 2 s .c o m Calendar t = Calendar.getInstance(); t.set(Calendar.HOUR_OF_DAY, 0); t.set(Calendar.MINUTE, 1); t.set(Calendar.SECOND, 0); if (c.after(t)) { NumberFormat nf = NumberFormat.getInstance(); nf.setMinimumIntegerDigits(2); return nf.format(c.get(Calendar.HOUR_OF_DAY)) + ":" + nf.format(c.get(Calendar.MINUTE)); } else { return TIME_NONE; } }
From source file:Main.java
public static String sGetDecimalStringAnyLocaleAs1Pt5LocalisedString(String value) { Locale theLocale = Locale.getDefault(); NumberFormat numberFormat = DecimalFormat.getInstance(theLocale); Number theNumber;//from w w w . j a va 2 s . c om try { theNumber = numberFormat.parse(value); } catch (ParseException e) { //value = sConvertDigits(value); String valueWithDot = value.replaceAll(",", "."); theNumber = Double.valueOf(valueWithDot); } // String.format uses the JVM's default locale. //String s = String.format(Locale.US, "%.2f", price); NumberFormat outputFormat = DecimalFormat.getInstance(theLocale); outputFormat.setMinimumIntegerDigits(1); outputFormat.setMinimumFractionDigits(5); outputFormat.setMaximumFractionDigits(5); String theStringResult = outputFormat.format(theNumber); //String theStringResult = String.format("%1.5f", theDoubleValue.doubleValue()); return theStringResult; }
From source file:Main.java
public static String getMatchingThresholdToString(int value) { double p = -value / 12.0; NumberFormat nf = NumberFormat.getPercentInstance(); nf.setMaximumFractionDigits(Math.max(0, (int) Math.ceil(-p) - 2)); nf.setMinimumIntegerDigits(1); return nf.format(Math.pow(10, p)); }
From source file:com.streamsets.pipeline.cluster.ClusterFunctionImpl.java
private static synchronized void initialize(Properties properties, Integer id, String rootDataDir) throws Exception { if (initialized) { return;/*from w w w . j a v a 2s . c om*/ } File dataDir = new File(System.getProperty("user.dir"), "data"); FileUtils.copyDirectory(new File(rootDataDir), dataDir); System.setProperty("sdc.data.dir", dataDir.getAbsolutePath()); // must occur before creating the EmbeddedSDCPool as // the hdfs target validation evaluates the sdc:id EL NumberFormat numberFormat = NumberFormat.getInstance(); numberFormat.setMinimumIntegerDigits(6); numberFormat.setGroupingUsed(false); final String sdcId = numberFormat.format(id); Utils.setSdcIdCallable(new Callable<String>() { @Override public String call() { return sdcId; } }); sdcPool = new EmbeddedSDCPool(properties); initialized = true; }
From source file:org.mycore.frontend.editor.MCREditorVariable.java
private static NumberFormat getSortFormater() { NumberFormat format = NumberFormat.getIntegerInstance(Locale.ROOT); format.setMinimumIntegerDigits(4); format.setGroupingUsed(false);// w ww. j a v a2s . c o m return format; }