Example usage for java.text NumberFormat format

List of usage examples for java.text NumberFormat format

Introduction

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

Prototype

public final String format(long number) 

Source Link

Document

Specialization of format.

Usage

From source file:com.haulmont.chile.core.datatypes.impl.IntegerDatatype.java

@Override
public String format(Object value, Locale locale) {
    if (value == null)
        return "";

    FormatStrings formatStrings = AppBeans.get(FormatStringsRegistry.class).getFormatStrings(locale);
    if (formatStrings == null)
        return format(value);

    DecimalFormatSymbols formatSymbols = formatStrings.getFormatSymbols();
    NumberFormat format = new DecimalFormat(formatStrings.getIntegerFormat(), formatSymbols);
    return format.format(value);
}

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

private String formatValue(Number pValue, NumberFormat pFormatter) {
    return (pValue.longValue() >= 0) ? "+" + pFormatter.format(pValue) : pFormatter.format(pValue);
}

From source file:com.haulmont.chile.core.datatypes.impl.LongDatatype.java

@Override
public String format(Object value, Locale locale) {
    if (value == null) {
        return "";
    }/*from   w w w  .j  a  v a  2s.c  om*/

    FormatStrings formatStrings = AppBeans.get(FormatStringsRegistry.class).getFormatStrings(locale);
    if (formatStrings == null) {
        return format(value);
    }

    DecimalFormatSymbols formatSymbols = formatStrings.getFormatSymbols();
    NumberFormat format = new DecimalFormat(formatStrings.getIntegerFormat(), formatSymbols);
    return format.format(value);
}

From source file:creative.framework.main.ApparelContext.java

private StringBuilder meansToString(List<Mean> means) {
    StringBuilder m = new StringBuilder();
    NumberFormat formatter = new DecimalFormat("#0.00");

    for (Mean mean : means) {
        m.append(formatter.format(mean.getResult())).append(" ");
    }// w ww . jav  a  2s . c  o m
    return m;
}

From source file:org.squale.squalecommon.enterpriselayer.facade.quality.MeasureFacade.java

/**
 * Creation d'une mesure de type Kiviat pour un projet
 * //from  w w w.j a  v  a  2s .c o m
 * @param pProjectId Id du projet
 * @param pAuditId Id de l'audit
 * @param pAllFactors tous les facteurs (= "true") ou seulement ceux ayant une note ?
 * @throws JrafEnterpriseException en cas de pb Hibernate
 * @return tableau d'objets : la map des donnes + le boolen pour affichage de la case  cocher tous les facteurs
 */
public static Object[] getProjectKiviat(Long pProjectId, Long pAuditId, String pAllFactors)
        throws JrafEnterpriseException {
    Map result = new HashMap();
    JFreeChart projectKiviat = null;
    MeasureDAOImpl measureDAO = MeasureDAOImpl.getInstance();
    // Session Hibernate
    ISession session = null;
    // Boolen conditonnanant l'affichage de la case  cocher "tous les facteurs" dans la page Jsp
    boolean displayCheckBoxFactors = true;
    try {
        // rcupration d'une session
        session = PERSISTENTPROVIDER.getSession();
        // On ajoute les notes de chaque projets sur le kiviat
        ProjectBO project = (ProjectBO) ProjectDAOImpl.getInstance().load(session, pProjectId);
        SortedMap values = new TreeMap();
        // recupere les facteurs du projet
        Collection factorResults = QualityResultDAOImpl.getInstance().findWhere(session, pProjectId, pAuditId);
        // et cree le map nom => note correspondant
        Iterator it = factorResults.iterator();
        ArrayList nullValuesList = new ArrayList();
        while (it.hasNext()) {
            FactorResultBO factor = (FactorResultBO) it.next();
            // le -1 est trait directement par le kiviatMaker
            Float value = new Float(factor.getMeanMark());
            // ajoute la note dans le titre
            // TODO prendre le vritable nom du facteur
            String name = factor.getRule().getName();
            if (value.floatValue() >= 0) {
                // avec 1 seul chiffre aprs la virgule
                NumberFormat nf = NumberFormat.getInstance();
                nf.setMinimumFractionDigits(1);
                nf.setMaximumFractionDigits(1);
                name = name + " (" + nf.format(value) + ")";
            } else {
                // Mmorisation temporaire des facteurs pour lesquels les notes sont nulles : sera utile si l'option
                // "Tous les facteurs" est coche pour afficher uniquement les facteurs ayant une note.
                nullValuesList.add(name);
            }
            values.put(name, value);
        }
        final int FACTORS_MIN = 3;
        if (nullValuesList.size() <= 0 || values.size() <= FACTORS_MIN) {
            displayCheckBoxFactors = false;
        }
        // Seulement les facteurs ayant une note ? ==> suppression des facteurs ayant une note nulle.
        // Mais trois facteurs doivent au moins s'afficher (nuls ou pas !)
        values = deleteFactors(values, nullValuesList, pAllFactors, FACTORS_MIN);

        // recupre le nom de l'audit
        String name = null;
        AuditBO audit = (AuditBO) AuditDAOImpl.getInstance().load(session, pAuditId);
        if (audit.getType().compareTo(AuditBO.MILESTONE) == 0) {
            name = audit.getName();
        }
        if (null == name) {
            DateFormat df = DateFormat.getDateInstance(DateFormat.LONG);
            name = df.format(audit.getDate());
        }
        result.put(name, values);

    } catch (Exception e) {
        FacadeHelper.convertException(e, MeasureFacade.class.getName() + ".getMeasures");
    } finally {
        FacadeHelper.closeSession(session, MeasureFacade.class.getName() + ".getMeasures");
    }
    Object[] kiviatObject = { result, new Boolean(displayCheckBoxFactors) };
    return kiviatObject;
}

From source file:com.pureinfo.srm.outlay.action.OutlayPrintEntryAction.java

private String getFormattedPercent(double _num) {
    NumberFormat format = new DecimalFormat("#.##");
    return format.format(_num);
}

From source file:creative.framework.main.ApparelContext.java

private StringBuilder variancesToString(List<Variance> variances) {
    StringBuilder v = new StringBuilder();
    NumberFormat formatter = new DecimalFormat("#0.00");
    for (Variance variance : variances) {
        v.append(formatter.format(variance.getResult())).append(" ");
    }/*from   w  w  w  .java2  s  . c om*/
    return v;
}

From source file:net.anthonypoon.ngram.correlation.CorrelationReducer.java

@Override
protected void reduce(Text key, Iterable<Text> values, Context context)
        throws IOException, InterruptedException {
    TreeMap<String, Double> currElement = new TreeMap();
    for (Text val : values) {
        String[] strArray = val.toString().split("\t");
        currElement.put(strArray[0], Double.valueOf(strArray[1]));
    }/*from  www  .  ja  v  a  2 s.c o m*/
    double[] currElementPrimitve = new double[upbound - lowbound + 1];
    for (Integer i = 0; i <= upbound - lowbound; i++) {
        if (currElement.containsKey(String.valueOf(lowbound + i - lag))) {
            currElementPrimitve[i] = currElement.get(String.valueOf(lowbound + i - lag));
        } else {
            currElementPrimitve[i] = 0;
        }

    }
    for (Map.Entry<String, TreeMap<String, Double>> pair : corrTargetArray.entrySet()) {
        double[] targetElemetPrimitive = new double[upbound - lowbound + 1];
        for (Integer i = 0; i <= upbound - lowbound; i++) {
            if (pair.getValue().containsKey(String.valueOf(lowbound + i))) {
                targetElemetPrimitive[i] = pair.getValue().get(String.valueOf(lowbound + i));
            } else {
                targetElemetPrimitive[i] = 0;
            }
        }
        Double correlation = new PearsonsCorrelation().correlation(targetElemetPrimitive, currElementPrimitve);
        if (correlation > threshold) {
            NumberFormat formatter = new DecimalFormat("#0.000");
            context.write(key, new Text(pair.getKey() + "\t" + formatter.format(correlation)));
        }
    }

}

From source file:com.pureinfo.srm.outlay.action.OutlayPrintEntryAction.java

private String getFormattedNum(double _num) {
    NumberFormat format = new DecimalFormat("#,###.######");
    return format.format(_num / 10000);
}

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.java 2 s .  c om*/
}