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.aurel.track.admin.customize.category.report.ReportBL.java

public static File getDirTemplate(Integer objectID) {
    if (objectID == null) {
        return null;
    }/*ww  w.  j av  a2 s. c  o  m*/
    NumberFormat nf = new DecimalFormat("00000");
    String dbId = nf.format(objectID);
    File dir;
    if (HandleHome.getTrackplus_Home() == null) {
        dir = new File(EXPORT_TEMPLATE_PREFIX + dbId);
    } else {
        dir = new File(HandleHome.getTrackplus_Home() + File.separator + HandleHome.REPORT_TEMPLATES_DIR
                + File.separator + EXPORT_TEMPLATE_PREFIX + dbId);
    }
    return dir;
}

From source file:dataGen.DataGen.java

/**
 * Creates normal or uniform distributed Test-Data, without correlation.
 * The resulting Data is stored in the resources Folder.
 * @param dimensions// ww  w  .  j av  a 2s  . c om
 *       The dimension count of the resulting Data
 * @param rowCount
 *       How many data tuples should be created?
 * @throws IOException
 *       If Stream to a File couldn't be written/closed 
 */
public static void genData(int dimensions, int rowCount) throws IOException {
    logger.info("Generating uniform random Data with " + rowCount + " Tuples in " + dimensions + " dimensions");
    Writer fw = new FileWriter("src/main/resources/random-" + rowCount + "-" + dimensions + ".dat");
    Random gen = new Random();

    for (int i = 1; i <= rowCount; i++) {
        // Each Row should start with the Row count
        String row = i + " ";
        // Files should be created OS/Language independent
        DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance();
        dfs.setDecimalSeparator('.');
        NumberFormat nf = new DecimalFormat("0.000000000", dfs);

        for (int j = 0; j < dimensions; j++) {
            Float n = gen.nextFloat();
            row = row + nf.format(n) + " ";
        }
        fw.write(row);
        fw.append(System.getProperty("line.separator"));
    }
    fw.close();
    logger.info(rowCount + " entries generated");
}

From source file:com.skubit.iab.activities.TransactionDetailsActivity.java

private static final String formatCurrencyAmount(BigDecimal balanceNumber) {
    NumberFormat numberFormat = NumberFormat.getInstance(Locale.getDefault());
    numberFormat.setMaximumFractionDigits(8);
    numberFormat.setMinimumFractionDigits(4);

    if (balanceNumber.compareTo(BigDecimal.ZERO) == -1) {
        balanceNumber = balanceNumber.multiply(new BigDecimal(-1));
    }// ww  w.j  a v  a 2s .  com

    return numberFormat.format(balanceNumber);
}

From source file:de.codesourcery.eve.skills.ui.renderer.SkillTreeRenderer.java

private static final String skillPointDeltaToString(long current, long maximumSkillpoints) {

    final float percent = 100.0f * ((float) current / (float) maximumSkillpoints);
    final NumberFormat FORMAT = new DecimalFormat("##0.00");

    if (current > 0) {
        final String label = Skill.skillPointsToString((int) current) + " SP ( " + FORMAT.format(percent)
                + " % )";
        return label;
    }/*from w w  w .jav  a2s .  co m*/
    return "";
}

From source file:com.kingcore.framework.util.ConvertUtils.java

/**
 * ?//from   w  w w . ja v  a2s .co m
 * Create on 2003-6-18
 * @param double 
 * @param int ???
 * @return
 * @throws Exception
 */
public static String formatNumber(double number, int scalar) throws Exception {
    String zero = "000000000000000000000000000000";
    String format = "##0." + zero.substring(0, scalar);
    NumberFormat nf = new DecimalFormat(format);
    return nf.format(number);
}

From source file:com.kingcore.framework.util.ConvertUtils.java

/**
 * ?/*ww  w  .ja v a 2s .com*/
 * Create on 2003-6-18
 * @param float 
 * @param int ???
 * @return
 * @throws Exception
 */
public static String formatNumber(float number, int scalar) throws Exception {
    String zero = "000000000000000000000000000000";
    String format = "##0." + zero.substring(0, scalar);
    NumberFormat nf = new DecimalFormat(format);
    return nf.format(number);
}

From source file:com.kingcore.framework.util.ConvertUtils.java

/**
 * ??/*  w  ww  . jav a 2s.  c o m*/
 * @param double ?
 * @param int ???
 * @param int ???
 * @return String
 */
public static String formatMoney(double money, int scalar) throws Exception {
    String zero = "000000000000000000000000000000";
    String format = "###,##0." + zero.substring(0, scalar);
    NumberFormat nf = new DecimalFormat(format);
    return nf.format(money);
}

From source file:com.kingcore.framework.util.ConvertUtils.java

/**
 * ??/*  w ww. j  a  va 2 s  . c o  m*/
 * @param String ?
 * @param int ???
 * @param int ???
 * @return String
 */
public static String formatMoney(float money, int scalar) throws Exception {
    String zero = "000000000000000000000000000000";
    String format = "###,##0." + zero.substring(0, scalar);
    NumberFormat nf = new DecimalFormat(format);
    return nf.format(money);
}

From source file:net.nosleep.superanalyzer.util.Misc.java

private static String formatCount(double value, String unitSingular, String unitPlural, boolean showFraction) {
    NumberFormat numberFormat = NumberFormat.getInstance();
    if (showFraction == true) {
        numberFormat.setMinimumFractionDigits(0);
        numberFormat.setMaximumFractionDigits(1);
    }//w  w  w .  j  a v a 2 s.co  m

    if (value > 1.0 && value < 1.01)
        return numberFormat.format(value) + " " + capitalizeByLocale(unitSingular);
    else
        return numberFormat.format(value) + " " + capitalizeByLocale(unitPlural);
}

From source file:Main.java

public static boolean isRTL(Locale locale, String symbol) {
    NumberFormat currencyFormat = NumberFormat.getCurrencyInstance(locale);

    // We then tell our formatter to use this symbol.
    DecimalFormatSymbols decimalFormatSymbols = ((java.text.DecimalFormat) currencyFormat)
            .getDecimalFormatSymbols();//from  www  .  j av a 2s  . co  m
    decimalFormatSymbols.setCurrencySymbol(symbol);
    ((java.text.DecimalFormat) currencyFormat).setDecimalFormatSymbols(decimalFormatSymbols);

    String formattedtext = currencyFormat.format(100.0);

    if (formattedtext.startsWith(symbol)) {
        return false;
    } else {
        return true;
    }

    /*
    final int directionality = Character.getDirectionality(String.format(locale,"%s",locale.getDisplayLanguage(locale)).charAt(0));
            
    if ( (directionality == Character.DIRECTIONALITY_RIGHT_TO_LEFT) ||
        (directionality == Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC) )
    {
    return true;
    }
    else
    {
    return false;
    }
     */
}