Example usage for java.text DecimalFormatSymbols setGroupingSeparator

List of usage examples for java.text DecimalFormatSymbols setGroupingSeparator

Introduction

In this page you can find the example usage for java.text DecimalFormatSymbols setGroupingSeparator.

Prototype

public void setGroupingSeparator(char groupingSeparator) 

Source Link

Document

Sets the character used for thousands separator.

Usage

From source file:com.epam.dlab.core.parser.CommonFormat.java

/**
 * Create and return decimal formatter./*from  w  ww.j  a v  a 2  s.c  om*/
 *
 * @param decimalSeparator  the character used for decimal sign.
 * @param groupingSeparator the character used for thousands separator.
 * @return Formatter for decimal digits.
 */
private DecimalFormat getDecimalFormat(char decimalSeparator, char groupingSeparator) {
    DecimalFormat df = new DecimalFormat();
    DecimalFormatSymbols symbols = new DecimalFormatSymbols();
    symbols.setDecimalSeparator(decimalSeparator);
    symbols.setGroupingSeparator(groupingSeparator);
    df.setDecimalFormatSymbols(symbols);
    return df;
}

From source file:fr.amap.lidar.PtgScanConversion.java

public void toTxt(SimpleScan scan, File outputDirectory, boolean exportRGB, boolean exportIntensity)
        throws IOException, Exception {

    /***Convert rxp to txt***/

    File outputTxtFile = new File(
            outputDirectory.getAbsolutePath() + File.separator + scan.file.getName() + ".txt");

    try (BufferedWriter writer = new BufferedWriter(new FileWriter(outputTxtFile))) {

        /**Transformation**/
        Mat4D popMatrix = scan.popMatrix;
        Mat4D sopMatrix = scan.sopMatrix;

        Mat4D transfMatrix = Mat4D.multiply(sopMatrix, popMatrix);

        Mat3D rotation = new Mat3D();
        rotation.mat = new double[] { transfMatrix.mat[0], transfMatrix.mat[1], transfMatrix.mat[2],
                transfMatrix.mat[4], transfMatrix.mat[5], transfMatrix.mat[6], transfMatrix.mat[8],
                transfMatrix.mat[9], transfMatrix.mat[10] };

        DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.getDefault());
        otherSymbols.setDecimalSeparator('.');
        otherSymbols.setGroupingSeparator('.');
        DecimalFormat strictFormat = new DecimalFormat("###.##", otherSymbols);

        String header = "directionX directionY directionZ x y z empty";

        if (exportIntensity) {
            header += " intensity";
        }//  w  w w.ja va  2s . c  o  m

        if (exportRGB) {
            header += " red green blue";
        }

        header += "\n";

        writer.write(header);

        PTGScan ptgScan = new PTGScan();
        ptgScan.openScanFile(scan.file);

        LPointShotExtractor shots = new LPointShotExtractor(ptgScan);
        Iterator<LShot> iterator = shots.iterator();

        int shotID = 0;

        while (iterator.hasNext()) {

            LShot shot = iterator.next();
            shot.direction.normalize();

            Vec4D origin = Mat4D.multiply(transfMatrix,
                    new Vec4D(shot.origin.x, shot.origin.y, shot.origin.z, 1.0d));
            Vec3D direction = Mat3D.multiply(rotation,
                    new Vec3D(shot.direction.x, shot.direction.y, shot.direction.z));
            direction = Vec3D.normalize(direction);

            SphericalCoordinates sc = new SphericalCoordinates();
            sc.toSpherical(new Vector3d(direction.x, direction.y, direction.z));

            short empty = 1;

            if (shot.ranges.length > 0) {
                empty = 0;
            }

            double x = origin.x + direction.x * 100;
            double y = origin.y + direction.y * 100;
            double z = origin.z + direction.z * 100;

            writer.write(direction.x + " " + direction.y + " " + direction.z + " " + x + " " + y + " " + z + " "
                    + empty + "\n");

            //                for(int i=0;i<shot.ranges.length;i++){
            //                    
            //                    double x = origin.x + direction.x * shot.ranges[i];
            //                    double y = origin.y + direction.y * shot.ranges[i];
            //                    double z = origin.z + direction.z * shot.ranges[i];
            //                    
            //                    String echo = shotID + " " + x + " " + y + " " + z + " " + direction.x + " " + direction.y+ " " + direction.z + " " + shot.ranges[i]+" "+shot.ranges.length+" "+i;
            //                    
            //                    if(exportIntensity){
            //                        echo += " " + strictFormat.format(shot.point.intensity);
            //                    }
            //                    
            //                    if(exportRGB){
            //                        echo += " " + strictFormat.format(shot.point.red);
            //                        echo += " " + strictFormat.format(shot.point.green);
            //                        echo += " " + strictFormat.format(shot.point.blue);
            //                    }
            //                    
            //                    echo += "\n";
            //                    
            //                    writer.write(echo);
            //                }

            shotID++;
        }
    } catch (Exception ex) {
        System.err.println(ex);
    }
}

From source file:com.magestore.app.pos.service.config.POSConfigService.java

private DecimalFormat integetFormat(ConfigPriceFormat priceFormat) {
    // khi to interger format
    String pattern = "###,###";
    Locale locale = new Locale("vi", "VN");
    DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.getDefault());
    symbols.setGroupingSeparator(priceFormat.getGroupSymbol().charAt(0));
    DecimalFormat format = new DecimalFormat(pattern, symbols);
    format.setGroupingSize(priceFormat.getGroupLength());
    return format;
}

From source file:org.openbravo.advpaymentmngt.utility.FIN_Utility.java

/**
 * Convert a multi currency amount to a string for display in the UI. If amount has been converted
 * to a different currency, then output that converted amount and currency as well
 * /*from www  . j av  a 2s  .c  o  m*/
 * @param amt
 *          Amount of payment
 * @param currency
 *          Currency payment was made in
 * @param convertedAmt
 *          Amount of payment in converted currency
 * @param convertedCurrency
 *          Currency payment was converted to/from
 * @return String version of amount formatted for display to user
 */
public static String multiCurrencyAmountToDisplay(BigDecimal amt, Currency currency, BigDecimal convertedAmt,
        Currency convertedCurrency) {
    StringBuffer out = new StringBuffer();
    final UIDefinitionController.FormatDefinition formatDef = UIDefinitionController.getInstance()
            .getFormatDefinition("euro", "Edition");

    String formatWithDot = formatDef.getFormat();
    DecimalFormatSymbols dfs = new DecimalFormatSymbols();
    try {
        dfs.setDecimalSeparator(formatDef.getDecimalSymbol().charAt(0));
        dfs.setGroupingSeparator(formatDef.getGroupingSymbol().charAt(0));
        // Use . as decimal separator
        final String DOT = ".";
        if (!DOT.equals(formatDef.getDecimalSymbol())) {
            formatWithDot = formatWithDot.replace(formatDef.getGroupingSymbol(), "@");
            formatWithDot = formatWithDot.replace(formatDef.getDecimalSymbol(), ".");
            formatWithDot = formatWithDot.replace("@", ",");
        }
    } catch (Exception e) {
        // If any error use euroEdition default format
        formatWithDot = "#0.00";
    }
    DecimalFormat amountFormatter = new DecimalFormat(formatWithDot, dfs);
    amountFormatter.setMaximumFractionDigits(currency.getStandardPrecision().intValue());

    out.append(amountFormatter.format(amt));
    if (convertedCurrency != null && !currency.equals(convertedCurrency)
            && amt.compareTo(BigDecimal.ZERO) != 0) {
        amountFormatter.setMaximumFractionDigits(convertedCurrency.getStandardPrecision().intValue());
        out.append(" (").append(amountFormatter.format(convertedAmt)).append(" ")
                .append(convertedCurrency.getISOCode()).append(")");
    }

    return out.toString();
}

From source file:org.openbravo.advpaymentmngt.utility.FIN_Utility.java

/**
 * Formats a number using the given format, decimal and grouping separator.
 * /*  w w w.  j a  v a2  s  .c om*/
 * @param number
 *          Number to be formatted.
 * @param javaFormat
 *          Java number format pattern.
 * @param _decimalSeparator
 *          Symbol used as decimal separator.
 * @param _groupingSeparator
 *          Symbol used as grouping separator.
 * @return Formatted string.
 */
public static String formatNumber(BigDecimal number, String javaFormat, String _decimalSeparator,
        String _groupingSeparator) {
    if (StringUtils.isEmpty(javaFormat)) {
        return formatNumber(number);
    }
    String decimalSeparator = _decimalSeparator;
    String groupingSeparator = _groupingSeparator;
    if (StringUtils.isEmpty(decimalSeparator) || StringUtils.isEmpty(groupingSeparator)) {
        decimalSeparator = ".";
        groupingSeparator = ",";
    }
    DecimalFormatSymbols dfs = new DecimalFormatSymbols();
    DecimalFormat dc;
    try {
        dfs.setDecimalSeparator(decimalSeparator.charAt(0));
        dfs.setGroupingSeparator(groupingSeparator.charAt(0));
        dc = new DecimalFormat(javaFormat, dfs);

    } catch (Exception e) {
        // If any error use euroEdition default format
        dc = new DecimalFormat("#0.00", dfs);
    }
    return dc.format(number);
}

From source file:org.openbravo.advpaymentmngt.utility.FIN_Utility.java

/**
 * Formats a number using the euroEdition (see Format.xml) format.
 * //from w  w  w. j a  v  a2 s  .  com
 * @param number
 *          Number to be formatted.
 * @return Formatted string.
 */
public static String formatNumber(BigDecimal number) {
    final UIDefinitionController.FormatDefinition formatDef = UIDefinitionController.getInstance()
            .getFormatDefinition("euro", "Edition");

    String formatWithDot = formatDef.getFormat();
    DecimalFormatSymbols dfs = new DecimalFormatSymbols();
    DecimalFormat amountFormatter;
    try {
        dfs.setDecimalSeparator(formatDef.getDecimalSymbol().charAt(0));
        dfs.setGroupingSeparator(formatDef.getGroupingSymbol().charAt(0));
        // Use . as decimal separator
        final String DOT = ".";
        if (!DOT.equals(formatDef.getDecimalSymbol())) {
            formatWithDot = formatWithDot.replace(formatDef.getGroupingSymbol(), "@");
            formatWithDot = formatWithDot.replace(formatDef.getDecimalSymbol(), ".");
            formatWithDot = formatWithDot.replace("@", ",");
        }
        amountFormatter = new DecimalFormat(formatWithDot, dfs);
    } catch (Exception e) {
        // If any error use euroEdition default format
        amountFormatter = new DecimalFormat("#0.00", dfs);
    }
    return amountFormatter.format(number);
}

From source file:com.magestore.app.pos.service.config.POSConfigService.java

private DecimalFormat currencyFormat(ConfigPriceFormat priceFormat) {
    // khi to currency format
    String pattern = "###,###.#";
    DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.getDefault());
    symbols.setDecimalSeparator('.');
    symbols.setGroupingSeparator('.');
    DecimalFormat currencyFormat = new DecimalFormat(pattern, symbols);
    currencyFormat.setGroupingSize(priceFormat.getGroupLength());
    currencyFormat.setMaximumFractionDigits(priceFormat.getPrecision());
    currencyFormat.setMinimumFractionDigits(priceFormat.getRequirePrecision());
    return currencyFormat;
}

From source file:com.magestore.app.pos.service.config.POSConfigService.java

private DecimalFormat currencyNosymbolFormat(ConfigPriceFormat priceFormat) {
    // khi to currency format
    String pattern = "###,###.#";
    DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.getDefault());
    symbols.setDecimalSeparator(priceFormat.getDecimalSymbol().charAt(0));
    symbols.setGroupingSeparator(priceFormat.getGroupSymbol().charAt(0));
    DecimalFormat currencyFormat = new DecimalFormat(pattern, symbols);
    currencyFormat.setGroupingSize(priceFormat.getGroupLength());
    currencyFormat.setMaximumFractionDigits(priceFormat.getPrecision());
    currencyFormat.setMinimumFractionDigits(priceFormat.getRequirePrecision());
    return currencyFormat;
}

From source file:com.magestore.app.pos.service.config.POSConfigService.java

private DecimalFormat floatFormat(ConfigPriceFormat priceFormat) {
    // khi to float format
    String pattern = "###,###.#";
    DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.getDefault());
    symbols.setDecimalSeparator(priceFormat.getDecimalSymbol().charAt(0));
    symbols.setGroupingSeparator(priceFormat.getGroupSymbol().charAt(0));
    DecimalFormat format = new DecimalFormat(pattern, symbols);
    format.setGroupingSize(priceFormat.getGroupLength());
    format.setMaximumFractionDigits(priceFormat.getPrecision());
    format.setMinimumFractionDigits(priceFormat.getRequirePrecision());
    return format;
}

From source file:com.magestore.app.pos.service.config.POSConfigService.java

private DecimalFormat quantityFormat(ConfigQuantityFormat quantityFormat) {
    // khi to interger format
    // khi to float format
    String pattern = "###,###.#";
    DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.getDefault());
    symbols.setDecimalSeparator(quantityFormat.getDecimalSymbol().charAt(0));
    symbols.setGroupingSeparator(quantityFormat.getGroupSymbol().charAt(0));
    DecimalFormat format = new DecimalFormat(pattern, symbols);
    format.setGroupingSize(quantityFormat.getGroupLength());
    format.setMaximumFractionDigits(quantityFormat.getPrecision());
    format.setMinimumFractionDigits(0);//from   ww  w  .j av a2 s  . c  om
    return format;
}