Example usage for java.text NumberFormat getInstance

List of usage examples for java.text NumberFormat getInstance

Introduction

In this page you can find the example usage for java.text NumberFormat getInstance.

Prototype

public static final NumberFormat getInstance() 

Source Link

Document

Returns a general-purpose number format for the current default java.util.Locale.Category#FORMAT FORMAT locale.

Usage

From source file:org.restdoc.api.util.RestDocObject.java

/**
 * @param fieldName//w  ww  . ja v  a 2s.  c  o  m
 * @return the value as Number
 * @throws ParseException
 */
@JsonIgnore
public Number getAdditionalNumber(final String fieldName) throws ParseException {
    final Object object = this.getAdditionalField(fieldName);
    if (object instanceof Number) {
        return (Number) object;
    }
    return NumberFormat.getInstance().parse(object.toString());
}

From source file:se.uu.it.cs.recsys.constraint.api.SolverAPI.java

public Set<List<se.uu.it.cs.recsys.api.type.Course>> getSolution(ConstraintSolverPreference pref) {
    //        try (AnnotationConfigApplicationContext ctx
    //                = new AnnotationConfigApplicationContext(ConstraintSolverSpringConfig.class)) {

    long startTime = System.currentTimeMillis();

    LOGGER.info("Starting solving CSP problem  ... ");

    Set<List<se.uu.it.cs.recsys.api.type.Course>> solutions = this.solver.getSolution(pref);

    long elapsed = System.currentTimeMillis() - startTime;

    LOGGER.info("CSP finished. Elapsed time: {} ms", NumberFormat.getInstance().format(elapsed));

    printSolution(solutions);//w w  w .  j a  va 2s .c o  m

    return solutions;

}

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.  ja va  2s.  c o m*/
        NumberFormat formater = NumberFormat.getInstance();
        formater.setMaximumFractionDigits(0);
        formater.setMinimumFractionDigits(0);
        return formater.format(value.setScale(0, RoundingMode.HALF_EVEN));
    }
}

From source file:de.tor.tribes.util.html.FightReportHTMLToolTipGenerator.java

public static String buildToolTip(FightReport pReport) {
    String res = pTemplateData;/*  w w w .j a  v a  2s. c o  m*/
    String[] tables = buildUnitTables(pReport);
    SimpleDateFormat f = new SimpleDateFormat("dd.MM.yy HH:mm:ss");
    NumberFormat nf = NumberFormat.getInstance();
    nf.setMinimumFractionDigits(0);
    nf.setMaximumFractionDigits(0);
    res = res.replaceAll(WINNER_STRING,
            ((pReport.isWon() ? "Der Angreifer hat gewonnen" : "Der Verteidiger hat gewonnen")));
    res = res.replaceAll(SEND_TIME, f.format(new Date(pReport.getTimestamp())));
    res = res.replaceAll(ATTACKER_TABLE, tables[0]);
    res = res.replaceAll(DEFENDER_TABLE, tables[1]);
    res = res.replaceAll(MISC_TABLES, buildMiscTables(pReport));
    res = res.replaceAll(LUCK_STRING, "Gl&uuml;ck (aus Sicht des Angreifers)");
    res = res.replaceAll(LUCK_BAR, buildLuckBar(pReport.getLuck()));
    res = res.replaceAll(MORAL, nf.format(pReport.getMoral()) + "%");
    nf.setMinimumFractionDigits(1);
    nf.setMaximumFractionDigits(1);
    res = res.replaceAll(LUCK_NEG,
            ((pReport.getLuck() < 0) ? "<b>" + nf.format(pReport.getLuck()) + "%</b>" : ""));
    res = res.replaceAll(LUCK_POS,
            ((pReport.getLuck() >= 0) ? "<b>" + nf.format(pReport.getLuck()) + "%</b>" : ""));
    res = res.replaceAll(LUCK_ICON1, "<img src=\""
            + ((pReport.getLuck() <= 0) ? FightReportHTMLToolTipGenerator.class.getResource("/res/rabe.png")
                    : FightReportHTMLToolTipGenerator.class.getResource("/res/rabe_grau.png"))
            + "\"/>");
    res = res.replaceAll(LUCK_ICON2, "<img src=\""
            + ((pReport.getLuck() >= 0) ? FightReportHTMLToolTipGenerator.class.getResource("/res/klee.png")
                    : FightReportHTMLToolTipGenerator.class.getResource("/res/klee_grau.png"))
            + "\"/>");
    res = res.replaceAll(ATTACKER, StringEscapeUtils.escapeHtml(pReport.getAttacker().getName()));
    res = res.replaceAll(SOURCE, StringEscapeUtils.escapeHtml(pReport.getSourceVillage().getFullName()));
    res = res.replaceAll(DEFENDER, StringEscapeUtils.escapeHtml(pReport.getDefender().getName()));
    res = res.replaceAll(TARGET, StringEscapeUtils.escapeHtml(pReport.getTargetVillage().getFullName()));
    res = res.replaceAll(RAM_DAMAGE,
            ((pReport.wasWallDamaged())
                    ? "Wall besch&auml;digt von Level <b>" + pReport.getWallBefore() + "</b> auf Level <b>"
                            + pReport.getWallAfter() + "</b>"
                    : ""));
    res = res.replaceAll(CATA_DAMAGE,
            ((pReport.wasBuildingDamaged()) ? pReport.getAimedBuilding() + " besch&auml;digt von Level <b>"
                    + pReport.getBuildingBefore() + "</b> auf Level <b>" + pReport.getBuildingAfter() + "</b>"
                    : ""));
    res = res.replaceAll(SNOB_INFLUENCE,
            ((pReport.wasSnobAttack())
                    ? "Zustimmung gesunken von <b>" + pReport.getAcceptanceBefore() + "</b> auf <b>"
                            + pReport.getAcceptanceAfter() + "</b>"
                    : ""));

    return res;
}

From source file:be.ibridge.kettle.trans.step.xmlinput.XMLInputData.java

/**
 * /*w  w w.j a  va 2  s .com*/
 */
public XMLInputData() {
    super();

    thisline = null;
    nextline = null;
    nf = NumberFormat.getInstance();
    df = (DecimalFormat) nf;
    dfs = new DecimalFormatSymbols();
    daf = new SimpleDateFormat();
    dafs = new DateFormatSymbols();

    nr_repeats = 0;
    previousRow = null;
    filenr = 0;

    fr = null;
    zi = null;
    is = null;
}

From source file:com.panet.imeta.trans.steps.propertyinput.PropertyInputData.java

/**
 * /*ww w  .  j  ava 2s  . c  o  m*/
 */
public PropertyInputData() {
    super();
    previousRow = null;
    thisline = null;
    nf = NumberFormat.getInstance();
    df = (DecimalFormat) nf;
    dfs = new DecimalFormatSymbols();
    daf = new SimpleDateFormat();
    dafs = new DateFormatSymbols();

    nr_repeats = 0;
    previousRow = null;
    filenr = 0;

    fr = null;
    is = null;
    rw = null;
    totalpreviousfields = 0;
    indexOfFilenameField = -1;
    readrow = null;
    pro = new Properties();
    it = null;
}

From source file:org.amanzi.awe.charts.builder.TimeChartBuilder.java

@Override
protected NumberAxis configRangeAxis(IRangeAxis axis) {
    NumberAxis rangeAxis;/*from  w ww.j av a2  s  .  c  o  m*/
    if (axis.equals(getModel().getMainRangeAxis())) {
        rangeAxis = (NumberAxis) getPlot().getRangeAxis();
        rangeAxis.setNumberFormatOverride(NumberFormat.getInstance());
        rangeAxis.getNumberFormatOverride().setMaximumFractionDigits(MAXIMUM_FRACTION_DIGITS);
    } else {
        rangeAxis = new NumberAxis(getModel().getSecondRangeAxis().getName());
        rangeAxis.setNumberFormatOverride(NumberFormat.getInstance());
        rangeAxis.getNumberFormatOverride().setMaximumFractionDigits(MAXIMUM_FRACTION_DIGITS);
        rangeAxis.setAutoRangeIncludesZero(false);
    }
    return rangeAxis;
}

From source file:com.alibaba.json.test.Bug_0_Test.java

private void f_jackson() throws Exception {
    long startNano = System.nanoTime();
    for (int i = 0; i < COUNT; ++i) {
        ObjectMapper mapper = new ObjectMapper();
        ArrayNode node = (ArrayNode) mapper.readTree(text);
        JsonNode head = node.get(0);/*from   w ww . ja  v a  2s . c o m*/
        JsonNode body = node.get(1);
    }
    long nano = System.nanoTime() - startNano;
    System.out.println(NumberFormat.getInstance().format(nano));
}

From source file:com.btobits.automator.ant.utils.task.RandomTask.java

@Override
public void execute() throws BuildException {
    if (min == null || min.equals(""))
        throw new BuildException("Min property not specified");

    if (max == null || max.equals(""))
        throw new BuildException("Max property not specified");

    if (type.equalsIgnoreCase("int") || StringUtils.isBlank(type)) {

        int minInt = Integer.parseInt(min);
        int maxInt = Integer.parseInt(max);

        if (minInt > maxInt)
            throw new BuildException("Min is bigger than max");

        int randomInt = calculateRandom(minInt, maxInt);
        getProject().setNewProperty(property, String.valueOf(randomInt));
    } else {//from   w  w w  .  j  a v a 2  s. c  o m

        double minD = Double.parseDouble(min);
        double maxD = Double.parseDouble(max);

        if (minD > maxD)
            throw new BuildException("Min is bigger than max");

        double randomDouble = calculateRandom2(minD, maxD);
        NumberFormat nf = NumberFormat.getInstance();
        nf.setMaximumFractionDigits(fraction);
        getProject().setNewProperty(property, nf.format(randomDouble));
    }

    try {
        Thread.sleep(1);
    } catch (InterruptedException e) {
    }
}

From source file:de.tor.tribes.util.bb.BasicFormatter.java

public NumberFormat getNumberFormatter(int pDigits) {
    NumberFormat f = NumberFormat.getInstance();
    f.setMaximumFractionDigits(0);//from  w ww  .  j  a  v  a 2  s  . co m
    f.setMinimumFractionDigits(0);
    if (pDigits < 10) {
        f.setMaximumIntegerDigits(1);
    } else if (pDigits < 100) {
        f.setMaximumIntegerDigits(2);
    } else if (pDigits < 1000) {
        f.setMaximumIntegerDigits(3);
    } else if (pDigits < 10000) {
        f.setMaximumIntegerDigits(4);
    } else {
        f.setMaximumIntegerDigits(5);
    }
    return f;
}