List of usage examples for java.text NumberFormat getInstance
public static NumberFormat getInstance(Locale inLocale)
From source file:com.salesmanager.core.module.impl.application.currencies.GenericCurrencyModule.java
public String getFormatedAmount(BigDecimal amount) throws Exception { // TODO Auto-generated method stub NumberFormat nf = null;/* w w w. j av a 2 s. com*/ Locale locale = Locale.US; if (this.decimalPoint == ',') { locale = Locale.GERMAN; } nf = NumberFormat.getInstance(locale); nf.setMaximumFractionDigits(Integer.parseInt(Character.toString(decimalCount))); nf.setMinimumFractionDigits(Integer.parseInt(Character.toString(decimalCount))); return nf.format(amount); }
From source file:com.ibm.replication.iidr.warehouse.CollectCDCStats.java
public CollectCDCStats(CollectCDCStatsParms parms) throws ConfigurationException, EmbeddedScriptException, IllegalAccessException, InstantiationException, ClassNotFoundException, SQLException, IOException, CollectCDCStatsParmsException { this.parms = parms; PropertiesConfiguration versionInfo = new PropertiesConfiguration( "conf" + File.separator + "version.properties"); logger = LogManager.getLogger(); logger.info("Version: " + versionInfo.getString("buildVersion") + "." + versionInfo.getString("buildRelease") + "." + versionInfo.getString("buildMod") + ", date: " + versionInfo.getString("buildDate")); // Debug logging? if (parms.debug) { LoggerContext ctx = (LoggerContext) LogManager.getContext(false); Configuration config = ctx.getConfiguration(); LoggerConfig loggerConfig = config.getLoggerConfig("com.ibm.replication.iidr"); loggerConfig.setLevel(Level.DEBUG); ctx.updateLoggers();//from w w w .j a va2 s . c o m } // Load settings settings = new Settings(parms.propertiesFile); // TODO Set locale hard-coded to avoid date conversion errors, to be // fixed later Locale.setDefault(new Locale("en", "US")); // Get current session's locale currentLocale = Locale.getDefault(); logger.debug("Current locale (language_country): " + currentLocale.toString() + ", metrics will be parsed according to this locale"); localNumberFormat = NumberFormat.getInstance(currentLocale); // Check if the event log bookmarks will be used if (settings.logEventsToDB || settings.logEventsToCsv) { bookmarks = new Bookmarks("EventLogBookmarks.properties"); } // Start the timer thread to flush the output on a regular basis timer = new Timer(settings); new Thread(timer).start(); // Create a script object to be used to execute CHCCLP commands script = new EmbeddedScript(); try { script.open(); while (keepOn) { processSubscriptions(); logger.info("Sleeping for " + settings.checkFrequencySeconds + " seconds"); Thread.sleep(settings.checkFrequencySeconds * 1000); } } catch (EmbeddedScriptException e1) { logger.error(e1.getMessage()); throw new EmbeddedScriptException(99, "Error in running CHCCLP script"); } catch (InterruptedException e) { logger.info("Stop of program requested"); } catch (Exception e2) { logger.error("Error while collecting status and statistics: " + e2.getMessage()); } finally { disconnectServerDS(); script.close(); disconnectFromDatabase(); } }
From source file:org.openmrs.web.controller.ConceptFormController.java
/** * Allows for other Objects to be used as values in input tags. Normally, only strings and lists * are expected/*w ww . j a v a 2s.c om*/ * * @see org.springframework.web.servlet.mvc.BaseCommandController#initBinder(javax.servlet.http.HttpServletRequest, * org.springframework.web.bind.ServletRequestDataBinder) */ @Override protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception { super.initBinder(request, binder); ConceptFormBackingObject commandObject = (ConceptFormBackingObject) binder.getTarget(); NumberFormat nf = NumberFormat.getInstance(Context.getLocale()); binder.registerCustomEditor(java.lang.Integer.class, new CustomNumberEditor(java.lang.Integer.class, nf, true)); binder.registerCustomEditor(java.lang.Double.class, new CustomNumberEditor(java.lang.Double.class, nf, true)); binder.registerCustomEditor(java.util.Date.class, new CustomDateEditor( SimpleDateFormat.getDateInstance(SimpleDateFormat.SHORT, Context.getLocale()), true)); binder.registerCustomEditor(org.openmrs.ConceptClass.class, new ConceptClassEditor()); binder.registerCustomEditor(org.openmrs.ConceptDatatype.class, new ConceptDatatypeEditor()); binder.registerCustomEditor(java.util.Collection.class, "concept.conceptSets", new ConceptSetsEditor(commandObject.getConcept().getConceptSets())); binder.registerCustomEditor(java.util.Collection.class, "concept.answers", new ConceptAnswersEditor(commandObject.getConcept().getAnswers(true))); binder.registerCustomEditor(org.openmrs.ConceptSource.class, new ConceptSourceEditor()); binder.registerCustomEditor(ConceptMapType.class, new ConceptMapTypeEditor()); binder.registerCustomEditor(ConceptReferenceTerm.class, new ConceptReferenceTermEditor()); }
From source file:com.prowidesoftware.swift.model.field.Field.java
/** * Format the given object as a money number without currency information in format * @param aValue/*from w w w. ja va 2 s . c om*/ * @return the formatted amount as String */ protected static String formatNumber(final Object aValue) { //create formatter for financial amounts final DecimalFormat fmt = new DecimalFormat("#,###.00"); final NumberFormat f = NumberFormat.getInstance(Locale.getDefault()); if (f instanceof DecimalFormat) { ((DecimalFormat) f).setDecimalSeparatorAlwaysShown(true); fmt.setDecimalFormatSymbols(((DecimalFormat) f).getDecimalFormatSymbols()); } final String formatted = fmt.format(aValue); return formatted; }
From source file:org.optaplanner.benchmark.impl.statistic.stepscore.StepScoreProblemStatistic.java
private XYPlot createPlot(BenchmarkReport benchmarkReport, int scoreLevelIndex) { Locale locale = benchmarkReport.getLocale(); NumberAxis xAxis = new NumberAxis("Time spent"); xAxis.setNumberFormatOverride(new MillisecondsSpentNumberFormat(locale)); NumberAxis yAxis = new NumberAxis("Step score level " + scoreLevelIndex); yAxis.setNumberFormatOverride(NumberFormat.getInstance(locale)); yAxis.setAutoRangeIncludesZero(false); XYPlot plot = new XYPlot(null, xAxis, yAxis, null); plot.setOrientation(PlotOrientation.VERTICAL); return plot;/* w ww.ja va2s.c om*/ }
From source file:mt.LengthDistribution.java
public static void GetLengthDistributionArray(ArrayList<File> AllMovies, double[] calibration) { ArrayList<Double> maxlist = new ArrayList<Double>(); for (int i = 0; i < AllMovies.size(); ++i) { double maxlength = LengthDistribution.Lengthdistro(AllMovies.get(i)); if (maxlength != Double.NaN && maxlength > 0) maxlist.add(maxlength);/*from ww w. j ava 2 s .com*/ } Collections.sort(maxlist); int min = 0; int max = (int) Math.round(maxlist.get(maxlist.size() - 1)) + 1; XYSeries counterseries = new XYSeries("MT length distribution"); XYSeries Logcounterseries = new XYSeries("MT Log length distribution"); final ArrayList<Point> points = new ArrayList<Point>(); for (int length = 0; length < max; ++length) { HashMap<Integer, Integer> frameseed = new HashMap<Integer, Integer>(); int count = 0; for (int i = 0; i < AllMovies.size(); ++i) { File file = AllMovies.get(i); double currentlength = LengthDistribution.Lengthdistro(file); ArrayList<FLSobject> currentobject = Tracking.loadMTStat(file); if (currentlength > length) { for (int index = 0; index < currentobject.size(); ++index) { ArrayList<Integer> seedlist = new ArrayList<Integer>(); if (currentobject.get(index).length >= length) { seedlist.add(currentobject.get(index).seedID); if (frameseed.get(currentobject.get(index).Framenumber) != null && frameseed.get(currentobject.get(index).Framenumber) != Double.NaN) { int currentcount = frameseed.get(currentobject.get(index).Framenumber); frameseed.put(currentobject.get(index).Framenumber, seedlist.size() + currentcount); } else if (currentobject.get(index) != null) frameseed.put(currentobject.get(index).Framenumber, seedlist.size()); } } } } // Get maxima length, count int maxvalue = Integer.MIN_VALUE; for (int key : frameseed.keySet()) { int Count = frameseed.get(key); if (Count >= maxvalue) maxvalue = Count; } if (maxvalue != Integer.MIN_VALUE) { counterseries.add(length, maxvalue); if (maxvalue > 0) { Logcounterseries.add((length), Math.log(maxvalue)); points.add(new Point(new double[] { length, Math.log(maxvalue) })); } } } final XYSeriesCollection dataset = new XYSeriesCollection(); final XYSeriesCollection nofitdataset = new XYSeriesCollection(); dataset.addSeries(counterseries); nofitdataset.addSeries(counterseries); final XYSeriesCollection Logdataset = new XYSeriesCollection(); Logdataset.addSeries(Logcounterseries); final JFreeChart chart = ChartFactory.createScatterPlot("MT length distribution", "Number of MT", "Length (micrometer)", dataset); final JFreeChart nofitchart = ChartFactory.createScatterPlot("MT length distribution", "Number of MT", "Length (micrometer)", nofitdataset); // Fitting line to log of the length distribution interpolation.Polynomial poly = new interpolation.Polynomial(1); try { poly.fitFunction(points); } catch (NotEnoughDataPointsException e) { // TODO Auto-generated catch block e.printStackTrace(); } DisplayPoints.display(nofitchart, new Dimension(800, 500)); dataset.addSeries(Tracking.drawexpFunction(poly, counterseries.getMinX(), counterseries.getMaxX(), 0.5, "Exponential fit")); NumberFormat nf = NumberFormat.getInstance(Locale.ENGLISH); nf.setMaximumFractionDigits(3); TextTitle legendText = new TextTitle("Mean Length" + " : " + nf.format(-1.0 / poly.getCoefficients(1)) + " " + "Standard Deviation" + " : " + nf.format(poly.SSE)); legendText.setPosition(RectangleEdge.RIGHT); DisplayPoints.display(chart, new Dimension(800, 500)); chart.addSubtitle(legendText); final JFreeChart logchart = ChartFactory.createScatterPlot("MT Log length distribution", "Number of MT", "Length (micrometer)", Logdataset); // DisplayPoints.display(logchart, new Dimension(800, 500)); for (int i = 1; i >= 0; --i) System.out.println(poly.getCoefficients(i) + " " + "x" + " X to the power of " + i); // Logdataset.addSeries(Tracking.drawFunction(poly, counterseries.getMinX(), counterseries.getMaxX(), 0.5, "Straight line fit")); WriteLengthdistroFile(AllMovies, counterseries, 0); }
From source file:org.optaplanner.benchmark.impl.statistic.bestscore.BestScoreProblemStatistic.java
private XYPlot createPlot(BenchmarkReport benchmarkReport, int scoreLevelIndex) { Locale locale = benchmarkReport.getLocale(); NumberAxis xAxis = new NumberAxis("Time spent"); xAxis.setNumberFormatOverride(new MillisecondsSpentNumberFormat(locale)); NumberAxis yAxis = new NumberAxis("Best score level " + scoreLevelIndex); yAxis.setNumberFormatOverride(NumberFormat.getInstance(locale)); yAxis.setAutoRangeIncludesZero(false); XYPlot plot = new XYPlot(null, xAxis, yAxis, null); plot.setOrientation(PlotOrientation.VERTICAL); return plot;//w w w . ja va 2s. c om }
From source file:com.salesmanager.core.module.impl.application.currencies.GenericCurrencyModule.java
public String getMeasure(BigDecimal measure, String currencycode) throws Exception { NumberFormat nf = null;//from w ww .j a v a2s . co m Locale locale = Locale.US; if (this.decimalPoint == ',') { locale = Locale.GERMAN; } nf = NumberFormat.getInstance(locale); nf.setMaximumFractionDigits(1); nf.setMinimumFractionDigits(1); measure.setScale(1, BigDecimal.ROUND_HALF_UP); return nf.format(measure); }
From source file:handlers.voicedcommands.WhoAmI.java
/** * Method useVoicedCommand.// ww w . j av a 2 s.c om * @param command String * @param player Player * @param args String * @return boolean * @see lineage2.gameserver.handlers.IVoicedCommandHandler#useVoicedCommand(String, Player, String) */ @Override public boolean useVoicedCommand(String command, Player player, String args) { Creature target = null; double hpRegen = Formulas.calcHpRegen(player); double cpRegen = Formulas.calcCpRegen(player); double mpRegen = Formulas.calcMpRegen(player); double hpDrain = player.calcStat(Stats.ABSORB_DAMAGE_PERCENT, 0., target, null); double mpDrain = player.calcStat(Stats.ABSORB_DAMAGEMP_PERCENT, 0., target, null); double hpGain = player.calcStat(Stats.HEAL_EFFECTIVNESS, 100., target, null); double mpGain = player.calcStat(Stats.MANAHEAL_EFFECTIVNESS, 100., target, null); double critPerc = 2 * player.calcStat(Stats.CRITICAL_DAMAGE, target, null); double critStatic = player.calcStat(Stats.CRITICAL_DAMAGE_STATIC, target, null); double mCritDmg = player.calcStat(Stats.MCRITICAL_DAMAGE, target, null); double blowRate = player.calcStat(Stats.FATALBLOW_RATE, target, null); ItemInstance shld = player.getSecondaryWeaponInstance(); boolean shield = (shld != null) && (shld.getItemType() == WeaponType.NONE); double shieldDef = shield ? player.calcStat(Stats.SHIELD_DEFENCE, player.getTemplate().getBaseShldDef(), target, null) : 0.; double shieldRate = shield ? player.calcStat(Stats.SHIELD_RATE, target, null) : 0.; double xpRate = player.getRateExp(); double spRate = player.getRateSp(); double dropRate = player.getRateItems(); double adenaRate = player.getRateAdena(); double spoilRate = player.getRateSpoil(); double fireResist = player.calcStat(Element.FIRE.getDefence(), 0., target, null); double windResist = player.calcStat(Element.WIND.getDefence(), 0., target, null); double waterResist = player.calcStat(Element.WATER.getDefence(), 0., target, null); double earthResist = player.calcStat(Element.EARTH.getDefence(), 0., target, null); double holyResist = player.calcStat(Element.HOLY.getDefence(), 0., target, null); double unholyResist = player.calcStat(Element.UNHOLY.getDefence(), 0., target, null); double bleedPower = player.calcStat(Stats.BLEED_POWER, target, null); double bleedResist = player.calcStat(Stats.BLEED_RESIST, target, null); double poisonPower = player.calcStat(Stats.POISON_POWER, target, null); double poisonResist = player.calcStat(Stats.POISON_RESIST, target, null); double stunPower = player.calcStat(Stats.STUN_POWER, target, null); double stunResist = player.calcStat(Stats.STUN_RESIST, target, null); double rootPower = player.calcStat(Stats.ROOT_POWER, target, null); double rootResist = player.calcStat(Stats.ROOT_RESIST, target, null); double sleepPower = player.calcStat(Stats.SLEEP_POWER, target, null); double sleepResist = player.calcStat(Stats.SLEEP_RESIST, target, null); double paralyzePower = player.calcStat(Stats.PARALYZE_POWER, target, null); double paralyzeResist = player.calcStat(Stats.PARALYZE_RESIST, target, null); double mentalPower = player.calcStat(Stats.MENTAL_POWER, target, null); double mentalResist = player.calcStat(Stats.MENTAL_RESIST, target, null); double debuffPower = player.calcStat(Stats.DEBUFF_POWER, target, null); double debuffResist = player.calcStat(Stats.DEBUFF_RESIST, target, null); double cancelPower = player.calcStat(Stats.CANCEL_POWER, target, null); double cancelResist = player.calcStat(Stats.CANCEL_RESIST, target, null); double swordResist = 100. - player.calcStat(Stats.SWORD_WPN_VULNERABILITY, target, null); double dualResist = 100. - player.calcStat(Stats.DUAL_WPN_VULNERABILITY, target, null); double bluntResist = 100. - player.calcStat(Stats.BLUNT_WPN_VULNERABILITY, target, null); double daggerResist = 100. - player.calcStat(Stats.DAGGER_WPN_VULNERABILITY, target, null); double bowResist = 100. - player.calcStat(Stats.BOW_WPN_VULNERABILITY, target, null); double crossbowResist = 100. - player.calcStat(Stats.CROSSBOW_WPN_VULNERABILITY, target, null); double poleResist = 100. - player.calcStat(Stats.POLE_WPN_VULNERABILITY, target, null); double fistResist = 100. - player.calcStat(Stats.FIST_WPN_VULNERABILITY, target, null); double critChanceResist = 100. - player.calcStat(Stats.CRIT_CHANCE_RECEPTIVE, target, null); double critDamResistStatic = player.calcStat(Stats.CRIT_DAMAGE_RECEPTIVE, target, null); double critDamResist = 100. - (100 * (player.calcStat(Stats.CRIT_DAMAGE_RECEPTIVE, 1., target, null) - critDamResistStatic)); String dialog = HtmCache.getInstance().getNotNull("command/whoami.htm", player); NumberFormat df = NumberFormat.getInstance(Locale.ENGLISH); df.setMaximumFractionDigits(1); df.setMinimumFractionDigits(1); StrBuilder sb = new StrBuilder(dialog); sb.replaceFirst("%hpRegen%", df.format(hpRegen)); sb.replaceFirst("%cpRegen%", df.format(cpRegen)); sb.replaceFirst("%mpRegen%", df.format(mpRegen)); sb.replaceFirst("%hpDrain%", df.format(hpDrain)); sb.replaceFirst("%mpDrain%", df.format(mpDrain)); sb.replaceFirst("%hpGain%", df.format(hpGain)); sb.replaceFirst("%mpGain%", df.format(mpGain)); sb.replaceFirst("%critPerc%", df.format(critPerc)); sb.replaceFirst("%critStatic%", df.format(critStatic)); sb.replaceFirst("%mCritDmg%", df.format(mCritDmg)); sb.replaceFirst("%blowRate%", df.format(blowRate)); sb.replaceFirst("%shieldDef%", df.format(shieldDef)); sb.replaceFirst("%shieldRate%", df.format(shieldRate)); sb.replaceFirst("%xpRate%", df.format(xpRate)); sb.replaceFirst("%spRate%", df.format(spRate)); sb.replaceFirst("%dropRate%", df.format(dropRate)); sb.replaceFirst("%adenaRate%", df.format(adenaRate)); sb.replaceFirst("%spoilRate%", df.format(spoilRate)); sb.replaceFirst("%fireResist%", df.format(fireResist)); sb.replaceFirst("%windResist%", df.format(windResist)); sb.replaceFirst("%waterResist%", df.format(waterResist)); sb.replaceFirst("%earthResist%", df.format(earthResist)); sb.replaceFirst("%holyResist%", df.format(holyResist)); sb.replaceFirst("%darkResist%", df.format(unholyResist)); sb.replaceFirst("%bleedPower%", df.format(bleedPower)); sb.replaceFirst("%bleedResist%", df.format(bleedResist)); sb.replaceFirst("%poisonPower%", df.format(poisonPower)); sb.replaceFirst("%poisonResist%", df.format(poisonResist)); sb.replaceFirst("%stunPower%", df.format(stunPower)); sb.replaceFirst("%stunResist%", df.format(stunResist)); sb.replaceFirst("%rootPower%", df.format(rootPower)); sb.replaceFirst("%rootResist%", df.format(rootResist)); sb.replaceFirst("%sleepPower%", df.format(sleepPower)); sb.replaceFirst("%sleepResist%", df.format(sleepResist)); sb.replaceFirst("%paralyzePower%", df.format(paralyzePower)); sb.replaceFirst("%paralyzeResist%", df.format(paralyzeResist)); sb.replaceFirst("%mentalPower%", df.format(mentalPower)); sb.replaceFirst("%mentalResist%", df.format(mentalResist)); sb.replaceFirst("%debuffPower%", df.format(debuffPower)); sb.replaceFirst("%debuffResist%", df.format(debuffResist)); sb.replaceFirst("%cancelPower%", df.format(cancelPower)); sb.replaceFirst("%cancelResist%", df.format(cancelResist)); sb.replaceFirst("%swordResist%", df.format(swordResist)); sb.replaceFirst("%dualResist%", df.format(dualResist)); sb.replaceFirst("%bluntResist%", df.format(bluntResist)); sb.replaceFirst("%daggerResist%", df.format(daggerResist)); sb.replaceFirst("%bowResist%", df.format(bowResist)); sb.replaceFirst("%crossbowResist%", df.format(crossbowResist)); sb.replaceFirst("%fistResist%", df.format(fistResist)); sb.replaceFirst("%poleResist%", df.format(poleResist)); sb.replaceFirst("%critChanceResist%", df.format(critChanceResist)); sb.replaceFirst("%critDamResist%", df.format(critDamResist)); NpcHtmlMessage msg = new NpcHtmlMessage(0); msg.setHtml(Strings.bbParse(sb.toString())); player.sendPacket(msg); return true; }
From source file:com.appdynamics.extensions.solr.SolrHelper.java
private static Double unLocalizeStrValue(String valueStr) { try {//from w ww .j a va 2s . co m Locale loc = Locale.getDefault(); return Double.valueOf(NumberFormat.getInstance(loc).parse(valueStr).doubleValue()); } catch (ParseException e) { LOG.error("Exception while unlocalizing number string " + valueStr, e); } return null; }