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.youTransactor.uCube.Tools.java

public static byte[] toBCD_double(double value, int length) {
    NumberFormat formatter = new DecimalFormat("#");
    String val = formatter.format(value);

    return hexStringToByteArray(StringUtils.leftPad(val, length * 2, '0'));
}

From source file:Utilities.java

public static String formatSize(long longSize, int decimalPos) {
    NumberFormat fmt = NumberFormat.getNumberInstance();
    if (decimalPos >= 0) {
        fmt.setMaximumFractionDigits(decimalPos);
    }/*w  ww  .j a v  a  2 s.  c o m*/
    final double size = longSize;
    double val = size / (1024 * 1024);
    if (val > 1) {
        return fmt.format(val).concat(" MB");
    }
    val = size / 1024;
    if (val > 10) {
        return fmt.format(val).concat(" KB");
    }
    return fmt.format(val).concat(" bytes");
}

From source file:Main.java

/**
 * //www .  j a va  2  s.  c  om
 * @param value
 * @param min_fraction_digit
 * @param max_fraction_digit
 * @return
 */
public static String formatNumber(double value, int min_fraction_digit, int max_fraction_digit) {
    NumberFormat nf;
    nf = NumberFormat.getInstance();

    if (min_fraction_digit != 0) {
        nf.setMinimumFractionDigits(min_fraction_digit);
    }

    if (max_fraction_digit != 0) {
        nf.setMaximumFractionDigits(max_fraction_digit);
    }

    return nf.format(value);
}

From source file:com.ms.app.web.commons.tools.CurrencyFormattor.java

/**
 * ?// w ww.j a v  a 2 s . com
 * 
 * @param number
 * @return
 */
public static String formatPercent(float number) {
    NumberFormat format = getFormat(PERCENT);
    return format.format(number);
}

From source file:com.doculibre.constellio.utils.FileSizeUtils.java

public static String formatSize(long fileSize, int decimalPos) {
    NumberFormat fmt = NumberFormat.getNumberInstance();
    if (decimalPos >= 0) {
        fmt.setMaximumFractionDigits(decimalPos);
    }/*from  w  w  w .  ja  v  a  2s.c  om*/
    final double size = fileSize;
    double val = size / (1024 * 1024);
    if (val > 1) {
        return fmt.format(val).concat(" MB");
    }
    val = size / 1024;
    if (val > 10) {
        return fmt.format(val).concat(" KB");
    }
    return fmt.format(val).concat(" bytes");
}

From source file:com.ms.app.web.commons.tools.CurrencyFormattor.java

/**
 * ????//from w  w w.ja v a2  s . co m
 * 
 * <pre>
 * format(null) 0.00
 * format(?1) 0.00
 * format(0) 0.00
 * format(1) 1.00
 * format(1000000) 10000.00
 * </pre>
 * 
 * @param price ?
 * @return 
 */
public static String format(Integer fen) {
    double yuan = 0;
    if (isNotNull(fen)) {
        yuan = fen / 100d;
    }
    NumberFormat numberInstance = getFormat(CURRENCY);
    return numberInstance.format(yuan);
}

From source file:com.ms.app.web.commons.tools.CurrencyFormattor.java

/**
 * ????<br>//from  w  ww.  j ava  2s .co  m
 * ,""
 * 
 * @param fen
 * @return
 */
public static String formatShowEmpty(Integer fen) {
    double yuan = 0;
    if (isNotNull(fen)) {
        yuan = fen / 100d;
        NumberFormat numberInstance = getFormat(CURRENCY);
        return numberInstance.format(yuan);
    }
    return "";
}

From source file:com.ms.app.web.commons.tools.CurrencyFormattor.java

/**
 * ?1??//from ww w. j  av  a  2s.  c o m
 * 
 * @param data
 * @param divide
 * @return
 */
public static String formatWith1Dot(Integer data, Double divide) {
    double result = 0;
    result = data / divide;
    NumberFormat numberInstance = getFormat(NUMBER);
    String strValue = numberInstance.format(result);
    // ???0
    if (strValue != null && strValue.length() > 0) {
        strValue = strValue.replaceAll("(\\.0+|0+)$", "");
    }
    return strValue;
}

From source file:com.ms.app.web.commons.tools.CurrencyFormattor.java

/**
 * ??/*www .  j a va 2 s .  co  m*/
 * 
 * @param data 
 * @param divide 
 * @return ???
 */

public static String format(Integer data, Double divide) {
    double result = 0;
    result = data / divide;
    NumberFormat numberInstance = getFormat(CURRENCY);
    String strValue = numberInstance.format(result);
    // ???0
    if (strValue != null && strValue.length() > 0) {
        strValue = strValue.replaceAll("(\\.0+|0+)$", "");
    }
    return strValue;
}

From source file:com.aurel.track.dbase.InitReportTemplateBL.java

/**
 * Extracts and copies the template definitions from the zips from the classpath
 * to the directory parallel with the attachment directory in the disk
 *
 *//*w w  w  .j  a v a  2 s  . co  m*/
public static void verifyReportTemplates() {
    LOGGER.info("Verifying report templates...");
    List<TExportTemplateBean> templatesList = ReportBL.getAllTemplates();

    int noOfDbTemplates = templatesList.size();
    int noOfNewlyInstalled = 0;

    for (int i = 0; i < templatesList.size(); i++) {
        TExportTemplateBean templateBean = templatesList.get(i);
        Integer templateID = templateBean.getObjectID();
        File f = ReportBL.getDirTemplate(templateID);
        LOGGER.debug("Move template:" + templateBean.getName() + " to" + f.getAbsolutePath());
        NumberFormat nf = new DecimalFormat("00000");
        String dbId = nf.format(templateID);
        String reportTemplateName = ReportBL.RESOURCE_PATH + "/" + ReportBL.EXPORT_TEMPLATE_PREFIX + dbId
                + ".zip";
        InputStream is = StartServlet.class.getClassLoader().getResourceAsStream(reportTemplateName);
        if (is == null) {
            //zip not found in the classpath: nothing to expand and copy
            continue;
        }
        if (!f.exists()) {
            boolean pathCreated = f.mkdirs();
            if (!pathCreated) {
                LOGGER.error("The destination directory " + f.getAbsolutePath() + " can't be created. "
                        + "This might be caused by OS file permissions or "
                        + "because the default directory lies inside the tomcat application. "
                        + "Set the attachment directory to a writable absolute path directory (outside tomcat) and restart tomcat");
                continue;
            }
        }
        ZipInputStream zf = new ZipInputStream(new BufferedInputStream(is));
        try {
            ReportBL.saveTemplate(templateID, zf);
            ++noOfNewlyInstalled;
        } catch (IOException e) {
            LOGGER.error("Can't move template:" + templateBean.getName() + "!", e);
        }
    }
    LOGGER.debug("Verifying report templates ready!");
    LOGGER.info("There are " + noOfDbTemplates + " report templates in the database; " + noOfNewlyInstalled
            + " were newly installed.");
}