List of usage examples for java.text NumberFormat format
public final String format(long number)
From source file:com.strider.datadefender.DataDefender.java
private static void displayExecutionTime(final long startTime) { final long endTime = System.currentTimeMillis(); final NumberFormat formatter = new DecimalFormat("#0.00000"); LOG.info("Execution time is " + formatter.format((endTime - startTime) / 1000d) + " seconds"); LOG.info("DataDefender completed "); }
From source file:is.landsbokasafn.deduplicator.heritrix.DeDuplicator.java
protected static String getPercentage(double portion, double total) { NumberFormat percentFormat = NumberFormat.getPercentInstance(Locale.ENGLISH); percentFormat.setMaximumFractionDigits(1); return percentFormat.format(portion / total); }
From source file:com.nridge.core.base.std.Platform.java
public static String bytesToString(long aSizeInBytes) { NumberFormat numberFormat = new DecimalFormat(); numberFormat.setMaximumFractionDigits(2); try {//from w w w . ja v a2 s . c om if (aSizeInBytes < FORMAT_SIZE_IN_KB) { return numberFormat.format(aSizeInBytes) + " byte(s)"; } else if (aSizeInBytes < FORMAT_SIZE_IN_MB) { return numberFormat.format(aSizeInBytes / FORMAT_SIZE_IN_KB) + " KB"; } else if (aSizeInBytes < FORMAT_SIZE_IN_GB) { return numberFormat.format(aSizeInBytes / FORMAT_SIZE_IN_MB) + " MB"; } else if (aSizeInBytes < FORMAT_SIZE_IN_TB) { return numberFormat.format(aSizeInBytes / FORMAT_SIZE_IN_GB) + " GB"; } else { return numberFormat.format(aSizeInBytes / FORMAT_SIZE_IN_TB) + " TB"; } } catch (Exception e) { return aSizeInBytes + " byte(s)"; } }
From source file:com.mongodb.hadoop.examples.wordcount.split.WordCountSplitTest.java
private final static void test(boolean useShards, boolean useChunks, Boolean slaveok, boolean useQuery) throws Exception { final Configuration conf = new Configuration(); MongoConfigUtil.setInputURI(conf, "mongodb://localhost:30000/test.lines"); conf.setBoolean(MongoConfigUtil.SPLITS_USE_SHARDS, useShards); conf.setBoolean(MongoConfigUtil.SPLITS_USE_CHUNKS, useChunks); if (useQuery) { //NOTE: must do this BEFORE Job is created final MongoConfig mongo_conf = new MongoConfig(conf); com.mongodb.BasicDBObject query = new com.mongodb.BasicDBObject(); query.put("num", new com.mongodb.BasicDBObject(Collections.singletonMap("$mod", new int[] { 2, 0 }))); System.out.println(" --- setting query on num"); mongo_conf.setQuery(query);/*from ww w.j a v a2 s.c o m*/ System.out.println(" --- query is: " + mongo_conf.getQuery()); } String output_table = null; if (useChunks) { if (useShards) output_table = "with_shards_and_chunks"; else output_table = "with_chunks"; } else { if (useShards) output_table = "with_shards"; else output_table = "no_splits"; } if (slaveok != null) { output_table += "_" + slaveok; } MongoConfigUtil.setOutputURI(conf, "mongodb://localhost:30000/test." + output_table); System.out.println("Conf: " + conf); final Job job = new Job(conf, "word count " + output_table); job.setJarByClass(WordCountSplitTest.class); job.setMapperClass(TokenizerMapper.class); job.setCombinerClass(IntSumReducer.class); job.setReducerClass(IntSumReducer.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(IntWritable.class); job.setInputFormatClass(MongoInputFormat.class); job.setOutputFormatClass(MongoOutputFormat.class); final long start = System.currentTimeMillis(); System.out.println(" ----------------------- running test " + output_table + " --------------------"); try { boolean result = job.waitForCompletion(true); System.out.println("job.waitForCompletion( true ) returned " + result); } catch (Exception e) { System.out.println("job.waitForCompletion( true ) threw Exception"); e.printStackTrace(); } final long end = System.currentTimeMillis(); final float seconds = ((float) (end - start)) / 1000; java.text.NumberFormat nf = java.text.NumberFormat.getInstance(); nf.setMaximumFractionDigits(3); System.out.println("finished run in " + nf.format(seconds) + " seconds"); com.mongodb.Mongo m = new com.mongodb.Mongo( new com.mongodb.MongoURI("mongodb://localhost:30000/?slaveok=true")); com.mongodb.DB db = m.getDB("test"); com.mongodb.DBCollection coll = db.getCollection(output_table); com.mongodb.BasicDBObject query = new com.mongodb.BasicDBObject(); query.put("_id", "the"); com.mongodb.DBCursor cur = coll.find(query); if (!cur.hasNext()) System.out.println("FAILURE: could not find count of \'the\'"); else System.out.println("'the' count: " + cur.next()); // if (! result) // System.exit( 1 ); }
From source file:com.netprogs.minecraft.plugins.social.command.util.MessageUtil.java
public static void sendNotEnoughFundsMessage(CommandSender sender, double price) { NumberFormat formatter = new DecimalFormat("###.00"); String itemDisplay = formatter.format(price); MessageUtil.sendMessage(sender, "social.error.notEnoughFunds", ChatColor.RED, new MessageParameter("<price>", itemDisplay, ChatColor.GOLD)); }
From source file:com.SCI.centraltoko.utility.UtilityTools.java
public static String formatNumber(BigDecimal value) { if (value == null || value.equals(BigDecimal.ZERO)) { return "0"; } else {//from w w w. jav a 2s . c om NumberFormat formater = NumberFormat.getInstance(); formater.setMaximumFractionDigits(0); formater.setMinimumFractionDigits(0); return formater.format(value.setScale(0, RoundingMode.HALF_EVEN)); } }
From source file:com.intuit.tank.project.JobDetailFormatter.java
protected static String calculateCost(TankConfig config, JobInstance proposedJobInstance, List<JobRegion> regions, long simulationTime) { List<VmInstanceType> instanceTypes = config.getVmManagerConfig().getInstanceTypes(); BigDecimal costPerHour = new BigDecimal(.5D); for (VmInstanceType type : instanceTypes) { if (type.getName().equals(proposedJobInstance.getVmInstanceType())) { costPerHour = new BigDecimal(type.getCost()); break; }//from ww w . j a va 2 s. c o m } long time = simulationTime + proposedJobInstance.getRampTime(); int numMachines = 0; for (JobRegion region : regions) { int users = Integer.parseInt(region.getUsers()); if (users > 0) { numMachines += (int) Math.ceil((double) users / (double) proposedJobInstance.getNumUsersPerAgent()); } } // dynamoDB costs about 1.5 times the instance cost BigDecimal cost = estimateCost(numMachines, costPerHour, time); NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US); return nf.format(cost.doubleValue()); }
From source file:io.stallion.utils.GeneralUtils.java
public static String formatCurrency(Double amt) { NumberFormat formatter = NumberFormat.getCurrencyInstance(); return formatter.format(amt); }
From source file:io.stallion.utils.GeneralUtils.java
public static String formatCurrency(Float amt) { NumberFormat formatter = NumberFormat.getCurrencyInstance(); return formatter.format(amt); }
From source file:com.gollahalli.web.WebViewer.java
/** * @param aDouble Input number to be converted * @param currentLocale Local builder//from w w w . ja v a2 s. c om * @return String */ static String displayCurrency(Double aDouble, Locale currentLocale) { NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(currentLocale); return currencyFormatter.format(aDouble); }