Example usage for java.text DecimalFormat setDecimalSeparatorAlwaysShown

List of usage examples for java.text DecimalFormat setDecimalSeparatorAlwaysShown

Introduction

In this page you can find the example usage for java.text DecimalFormat setDecimalSeparatorAlwaysShown.

Prototype

public void setDecimalSeparatorAlwaysShown(boolean newValue) 

Source Link

Document

Allows you to set the behavior of the decimal separator with integers.

Usage

From source file:com.blackbear.flatworm.converters.CoreConverters.java

public String convertDecimal(Object obj, Map<String, ConversionOption> options) {
    Double d = (Double) obj;
    if (d == null) {
        return null;
    }/*from www.j  a  v a2 s.  c o  m*/

    int decimalPlaces = 0;
    ConversionOption conv = (ConversionOption) options.get("decimal-places");

    String decimalPlacesOption = null;
    if (null != conv)
        decimalPlacesOption = conv.getValue();

    boolean decimalImplied = "true".equals(Util.getValue(options, "decimal-implied"));

    if (decimalPlacesOption != null)
        decimalPlaces = Integer.parseInt(decimalPlacesOption);

    DecimalFormat format = new DecimalFormat();
    format.setDecimalSeparatorAlwaysShown(!decimalImplied);
    format.setGroupingUsed(false);
    if (decimalImplied) {
        format.setMaximumFractionDigits(0);
        d = new Double(d.doubleValue() * Math.pow(10D, decimalPlaces));
    } else {
        format.setMinimumFractionDigits(decimalPlaces);
        format.setMaximumFractionDigits(decimalPlaces);
    }
    return format.format(d);
}

From source file:org.sakaiproject.tool.assessment.data.dao.grading.MediaData.java

public String getFileSizeKBFormat() {
    String fileSizeKBStr = "";
    if (fileSize != null) {
        double fileSizeKB = fileSize.doubleValue() / 1000;
        DecimalFormat nf = new DecimalFormat();
        nf.setMaximumFractionDigits(2);/*from   w  ww .  j  a  va2 s.  com*/
        nf.setDecimalSeparatorAlwaysShown(true);
        fileSizeKBStr = nf.format(fileSizeKB);
    }
    return fileSizeKBStr;
}

From source file:com.shopify.sample.activity.CheckoutActivity.java

public void startPayment() {
    /**/*  ww w .j  ava 2  s.  c o m*/
     * Replace with your public key
     */
    final String public_key = "rzp_live_ILgsfZCZoFIKMb";

    /**
     * You need to pass current activity in order to let razorpay create CheckoutActivity
     */
    final Activity activity = this;

    final com.razorpay.Checkout co = new com.razorpay.Checkout();
    co.setPublicKey(public_key);

    try {
        JSONObject options = new JSONObject("{" + "description: 'Demoing Charges',"
                + "image: 'https://rzp-mobile.s3.amazonaws.com/images/rzp.png'," + "currency: 'INR'}");
        final Checkout checkout = getSampleApplication().getCheckout();

        DecimalFormat decimalFormat = new DecimalFormat(".");
        decimalFormat.setGroupingUsed(false);
        decimalFormat.setDecimalSeparatorAlwaysShown(false);
        String amount = decimalFormat.format(Double.valueOf(checkout.getPaymentDue()) * 100);
        options.put("amount", amount);
        options.put("name", "Razorpay Corp");
        options.put("prefill", new JSONObject("{email: 'sm@razorpay.com', contact: '9876543210'}"));
        Log.d("RZP Json is", options.toString());
        co.open(activity, options);

    } catch (Exception e) {
        Toast.makeText(activity, e.getMessage(), Toast.LENGTH_SHORT).show();
        e.printStackTrace();
    }
}

From source file:com.shopify.sample.activity.CheckoutActivity.java

public void startPaytmPayment() {

    PaytmPGService Service = PaytmPGService.getStagingService();
    Map<String, String> paramMap = new HashMap<String, String>();
    final Checkout checkout1 = getSampleApplication().getCheckout();

    DecimalFormat decimalFormat = new DecimalFormat(".");
    decimalFormat.setGroupingUsed(false);
    decimalFormat.setDecimalSeparatorAlwaysShown(false);
    String amount = checkout1.getPaymentDue();
    // these are mandatory parameters

    paramMap.put("ORDER_ID", checkout1.getToken());
    paramMap.put("MID", "Variet41832464800424");
    paramMap.put("CUST_ID", checkout1.getCustomerId().toString());
    paramMap.put("CHANNEL_ID", "WAP");
    paramMap.put("INDUSTRY_TYPE_ID", "Retail");
    paramMap.put("WEBSITE", "APP_URL");
    paramMap.put("TXN_AMOUNT", amount);
    paramMap.put("THEME", "merchant");
    paramMap.put("EMAIL", "ankit81008@gmail.com");
    paramMap.put("MOBILE_NO", "9886000725");
    PaytmOrder Order = new PaytmOrder(paramMap);

    PaytmMerchant Merchant = new PaytmMerchant("http://www.3deestudio.com/myshop/paytm/generateChecksum.php",
            "http://www.3deestudio.com/myshop/paytm/verifyChecksum.php");

    Service.initialize(Order, Merchant, null);

    Service.startPaymentTransaction(this, true, true, new PaytmPaymentTransactionCallback() {
        @Override/*from  w w  w.j ava  2  s .c om*/
        public void someUIErrorOccurred(String inErrorMessage) {
            // Some UI Error Occurred in Payment Gateway Activity.
            // // This may be due to initialization of views in
            // Payment Gateway Activity or may be due to //
            // initialization of webview. // Error Message details
            // the error occurred.
        }

        @Override
        public void onTransactionSuccess(Bundle inResponse) {
            // After successful transaction this method gets called.
            // // Response bundle contains the merchant response
            // parameters.
            Log.d("LOG", "Payment Transaction is successful " + inResponse.toString());
            findViewById(R.id.discount_row).setVisibility(View.VISIBLE);
            ((TextView) findViewById(R.id.razorpayPaymentID)).setText(inResponse.toString());
            ((TextView) findViewById(R.id.razorpayPaymentStatus)).setText("Success");
            Toast.makeText(getApplicationContext(), "Payment Transaction is successful ", Toast.LENGTH_LONG)
                    .show();
        }

        @Override
        public void onTransactionFailure(String inErrorMessage, Bundle inResponse) {
            // This method gets called if transaction failed. //
            // Here in this case transaction is completed, but with
            // a failure. // Error Message describes the reason for
            // failure. // Response bundle contains the merchant
            // response parameters.
            Log.d("LOG", "Payment Transaction Failed " + inErrorMessage);
            findViewById(R.id.discount_row).setVisibility(View.VISIBLE);
            ((TextView) findViewById(R.id.razorpayPaymentID)).setText(inErrorMessage);
            ((TextView) findViewById(R.id.razorpayPaymentStatus)).setText("failure");
            Toast.makeText(getBaseContext(), "Payment Transaction Failed ", Toast.LENGTH_LONG).show();
        }

        @Override
        public void networkNotAvailable() { // If network is not
            // available, then this
            // method gets called.
            Toast.makeText(getBaseContext(), "networkNotAvailable ", Toast.LENGTH_LONG).show();
        }

        @Override
        public void clientAuthenticationFailed(String inErrorMessage) {
            // This method gets called if client authentication
            // failed. // Failure may be due to following reasons //
            // 1. Server error or downtime. // 2. Server unable to
            // generate checksum or checksum response is not in
            // proper format. // 3. Server failed to authenticate
            // that client. That is value of payt_STATUS is 2. //
            // Error Message describes the reason for failure.
            Toast.makeText(getBaseContext(), "clientAuthenticationFailed ", Toast.LENGTH_LONG).show();
        }

        @Override
        public void onErrorLoadingWebPage(int iniErrorCode, String inErrorMessage, String inFailingUrl) {
            Toast.makeText(getBaseContext(), "onErrorLoadingWebPage ", Toast.LENGTH_LONG).show();
        }

        // had to be added: NOTE
        @Override
        public void onBackPressedCancelTransaction() {
            // TODO Auto-generated method stub
            Toast.makeText(getBaseContext(), "onBackPressedCancelTransaction ", Toast.LENGTH_LONG).show();
        }

    });

}

From source file:com.dream.messaging.engine.DataHandler.java

/**
 * Format the number by the given pattern.
 * //from  w  ww. jav  a2  s . com
 * @param number the number
 * @param pattern the pattern
 * 
 * @return the string
 */
protected String format(Number number, String pattern) {
    java.text.DecimalFormat decFmt = new java.text.DecimalFormat(pattern);
    decFmt.setDecimalSeparatorAlwaysShown(false);
    return decFmt.format(number);

}

From source file:org.mifos.platform.accounting.service.AccountingDataCacheManager.java

private String parseNumber(String number) {
    // FIXME should use this from common util
    StringBuilder pattern = new StringBuilder();
    DecimalFormat decimalFormat = (DecimalFormat) DecimalFormat.getCurrencyInstance(Locale.ENGLISH);
    for (Short i = 0; i < DIGITS_BEFORE_DECIMAL; i++) {
        pattern.append('#');
    }//w  w w. j a v a 2  s  .co  m
    pattern.append(decimalFormat.getDecimalFormatSymbols().getDecimalSeparator());
    for (short i = 0; i < getDigitsAfterDecimal(); i++) {
        pattern.append('#');
    }
    decimalFormat.applyLocalizedPattern(pattern.toString());
    decimalFormat.setDecimalSeparatorAlwaysShown(false);
    decimalFormat.setMinimumFractionDigits(getDigitsAfterDecimal());
    return decimalFormat.format(Double.parseDouble(number));
}

From source file:lirmm.inria.fr.math.BigSparseRealMatrix.java

@Override
public String toString() {
    DecimalFormat df;
    df = new DecimalFormat();
    df.setMaximumFractionDigits(2); //arrondi  2 chiffres apres la virgules
    df.setMinimumFractionDigits(2);/*from   ww w  .  ja v  a 2s  .c o m*/
    df.setDecimalSeparatorAlwaysShown(true);
    String out = "";
    for (int i = 0; i < getRowDimension(); i++) {
        String o = "";
        for (int j = 0; j < getColumnDimension(); j++) {
            out += df.format(getEntry(i, j)).replaceAll(",", ".") + " ";
            o += df.format(getEntry(i, j)).replaceAll(",", ".") + " ";
        }
        out += "\n";
    }
    return out;
}

From source file:dbseer.gui.panel.DBSeerMiddlewarePanel.java

private void initializeGUI() {
    this.setLayout(new MigLayout());

    JLabel ipAddressLabel = new JLabel("IP Address:");
    JLabel portLabel = new JLabel("Port:");
    JLabel idLabel = new JLabel("ID:");
    JLabel passwordLabel = new JLabel("Password:");

    ipField = new JTextField(20);

    DecimalFormat portFormatter = new DecimalFormat();

    portFormatter.setMaximumFractionDigits(0);
    portFormatter.setMaximumIntegerDigits(5);
    portFormatter.setMinimumIntegerDigits(1);
    portFormatter.setDecimalSeparatorAlwaysShown(false);
    portFormatter.setGroupingUsed(false);

    portField = new JFormattedTextField(portFormatter);
    portField.setColumns(6);//  w  w w . jav a  2  s  .c  om
    portField.setText("3555"); // default port.
    idField = new JTextField(20);
    passwordField = new JPasswordField(20);

    logInOutButton = new JButton("Login");
    logInOutButton.addActionListener(this);
    startMonitoringButton = new JButton("Start Monitoring");
    startMonitoringButton.addActionListener(this);
    stopMonitoringButton = new JButton("Stop Monitoring");
    stopMonitoringButton.addActionListener(this);

    startMonitoringButton.setEnabled(true);
    stopMonitoringButton.setEnabled(false);

    ipField.setText(DBSeerGUI.userSettings.getLastMiddlewareIP());
    portField.setText(String.valueOf(DBSeerGUI.userSettings.getLastMiddlewarePort()));
    idField.setText(DBSeerGUI.userSettings.getLastMiddlewareID());

    NumberFormatter formatter = new NumberFormatter(NumberFormat.getIntegerInstance());
    formatter.setMinimum(1);
    formatter.setMaximum(120);
    formatter.setAllowsInvalid(false);

    refreshRateLabel = new JLabel("Monitoring Refresh Rate:");
    refreshRateField = new JFormattedTextField(formatter);
    JLabel refreshRateRangeLabel = new JLabel("(1~120 sec)");

    refreshRateField.setText("1");
    applyRefreshRateButton = new JButton("Apply");
    applyRefreshRateButton.addActionListener(this);

    this.add(ipAddressLabel, "cell 0 0 2 1, split 4");
    this.add(ipField);
    this.add(portLabel);
    this.add(portField);
    this.add(idLabel, "cell 0 2");
    this.add(idField, "cell 1 2");
    this.add(passwordLabel, "cell 0 3");
    this.add(passwordField, "cell 1 3");
    this.add(refreshRateLabel, "cell 0 4");
    this.add(refreshRateField, "cell 1 4, growx, split 3");
    this.add(refreshRateRangeLabel);
    this.add(applyRefreshRateButton, "growx, wrap");
    //      this.add(logInOutButton, "cell 0 2 2 1, growx, split 3");
    this.add(startMonitoringButton);
    this.add(stopMonitoringButton);
}

From source file:org.geomajas.layer.wms.WmsLayer.java

/**
 * Build the base part of the url (doesn't change for getMap or getFeatureInfo requests).
 * /*from w  w  w  . j a v a 2  s .c  o m*/
 * @param targetUrl
 *            base url
 * @param width
 *            image width
 * @param height
 *            image height
 * @param box
 *            bounding box
 * @return base WMS url
 * @throws GeomajasException
 *             missing parameter
 */
private StringBuilder formatBaseUrl(String targetUrl, int width, int height, Bbox box)
        throws GeomajasException {
    try {
        StringBuilder url = new StringBuilder(targetUrl);
        int pos = url.lastIndexOf("?");
        if (pos > 0) {
            url.append("&SERVICE=WMS");
        } else {
            url.append("?SERVICE=WMS");
        }
        String layers = getId();
        if (layerInfo.getDataSourceName() != null) {
            layers = layerInfo.getDataSourceName();
        }
        url.append("&layers=");
        url.append(URLEncoder.encode(layers, "UTF8"));
        url.append("&WIDTH=");
        url.append(Integer.toString(width));
        url.append("&HEIGHT=");
        url.append(Integer.toString(height));
        DecimalFormat decimalFormat = new DecimalFormat(); // create new as this is not thread safe
        decimalFormat.setDecimalSeparatorAlwaysShown(false);
        decimalFormat.setGroupingUsed(false);
        decimalFormat.setMinimumFractionDigits(0);
        decimalFormat.setMaximumFractionDigits(100);
        DecimalFormatSymbols symbols = new DecimalFormatSymbols();
        symbols.setDecimalSeparator('.');
        decimalFormat.setDecimalFormatSymbols(symbols);

        url.append("&bbox=");
        url.append(decimalFormat.format(box.getX()));
        url.append(",");
        url.append(decimalFormat.format(box.getY()));
        url.append(",");
        url.append(decimalFormat.format(box.getMaxX()));
        url.append(",");
        url.append(decimalFormat.format(box.getMaxY()));
        url.append("&format=");
        url.append(format);
        url.append("&version=");
        url.append(version);
        if ("1.3.0".equals(version)) {
            url.append("&crs=");
        } else {
            url.append("&srs=");
        }
        url.append(URLEncoder.encode(layerInfo.getCrs(), "UTF8"));
        url.append("&styles=");
        url.append(styles);
        if (null != parameters) {
            for (Parameter p : parameters) {
                url.append("&");
                url.append(URLEncoder.encode(p.getName(), "UTF8"));
                url.append("=");
                url.append(URLEncoder.encode(p.getValue(), "UTF8"));
            }
        }
        if (useProxy && null != securityContext.getToken()) {
            url.append("&userToken=");
            url.append(securityContext.getToken());
        }
        return url;
    } catch (UnsupportedEncodingException uee) {
        throw new IllegalStateException("Cannot find UTF8 encoding?", uee);
    }
}

From source file:org.egov.works.services.WorksService.java

public String toCurrency(final double money) {
    final double rounded = Math.round(money * 100) / 100.0;
    final DecimalFormat formatter = new DecimalFormat("0.00");
    formatter.setDecimalSeparatorAlwaysShown(true);
    return formatter.format(rounded);
}