Example usage for java.text DecimalFormat setGroupingUsed

List of usage examples for java.text DecimalFormat setGroupingUsed

Introduction

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

Prototype

@Override
public void setGroupingUsed(boolean newValue) 

Source Link

Usage

From source file:org.opensingular.form.wicket.mapper.DecimalMapper.java

private String formatDecimal(BigDecimal bigDecimal, boolean groupingUsed) {
    DecimalFormat nf = (DecimalFormat) DecimalFormat.getInstance(new Locale("pt", "BR"));
    nf.setParseBigDecimal(true);/*from w w  w .j  a  v  a 2  s .c  o m*/
    nf.setGroupingUsed(groupingUsed);
    nf.setMinimumFractionDigits(0);
    nf.setMaximumFractionDigits(bigDecimal.scale());
    return nf.format(bigDecimal);
}

From source file:nl.strohalm.cyclos.entities.accounts.external.filemapping.FileMappingWithFields.java

/**
 * Returns a converter for amount/*from  w ww  .j a va  2  s  .  co  m*/
 */
public Converter<BigDecimal> getNumberConverter() {
    if (numberFormat == NumberFormat.FIXED_POSITION) {
        return new FixedLengthNumberConverter<BigDecimal>(BigDecimal.class, decimalPlaces);
    } else {
        final DecimalFormatSymbols symbols = new DecimalFormatSymbols();
        symbols.setDecimalSeparator(decimalSeparator);
        symbols.setGroupingSeparator('!');

        final DecimalFormat format = new DecimalFormat("0." + StringUtils.repeat("0", decimalPlaces), symbols);
        format.setGroupingUsed(false);
        return new NumberConverter<BigDecimal>(BigDecimal.class, format);
    }
}

From source file:org.arkanos.aos.api.data.Work.java

@Override
public String toString() {
    DecimalFormat df = new DecimalFormat();
    df.setMaximumFractionDigits(1);/*from w ww . j  ava  2  s. c  o  m*/
    df.setGroupingUsed(false);
    SimpleDateFormat sdf = new SimpleDateFormat(Work.DATEFORMAT);
    String result = "{\"";
    try {
        result += "id\":\"" + this.task_id + "_" + sdf.parse(this.start).getTime() + "\",\"";
        result += Work.FIELD_TASK_ID + "\":" + this.task_id + ",\"";
        result += Work.FIELD_START + "\":\"" + this.start.substring(0, this.start.indexOf(".")) + "\",\"";
        result += Work.FIELD_COMMENT + "\":\"" + JSONObject.escape(this.comment) + "\",\"";
        result += Work.FIELD_RESULT + "\":" + this.result + ",\"";
        result += Work.FIELD_TIME_SPENT + "\":" + df.format(this.time_spent / 60.0f) + ",\"";
        result += Work.EXTRA_TASK_NAME + "\":\"" + this.task_name + "\",\"";
        result += Work.EXTRA_GOAL_TITLE + "\":\"" + this.goal_title + "\"}";
    } catch (ParseException e) {
        Log.error("Work", "Problems while parsing Work to a JSON.");
        e.printStackTrace();
        return "{\"error\":\"parsing\"}";
    }
    return result;
}

From source file:org.opensingular.form.wicket.mapper.MoneyMapper.java

private String formatDecimal(BigDecimal bigDecimal, Integer casasDecimais) {
    DecimalFormat nf = (DecimalFormat) DecimalFormat.getInstance(new Locale("pt", "BR"));
    nf.setParseBigDecimal(true);/*  w w w. jav  a  2s . c  o m*/
    nf.setGroupingUsed(true);
    nf.setMinimumFractionDigits(casasDecimais);
    nf.setMaximumFractionDigits(casasDecimais);
    return nf.format(bigDecimal);
}

From source file:org.intermine.bio.dataconversion.FlyAtlasConverter.java

private String round(String num, int dp) {
    double d = Double.parseDouble(num);
    DecimalFormat format = (DecimalFormat) DecimalFormat.getInstance();
    format.setMaximumFractionDigits(dp);
    format.setGroupingUsed(false);
    return format.format(d);
}

From source file:org.arkanos.aos.api.data.Task.java

@Override
public String toString() {
    DecimalFormat df = new DecimalFormat();
    df.setMaximumFractionDigits(1);/*from  w  w  w .jav a 2s  . c o m*/
    df.setGroupingUsed(false);
    String result = "{\"";
    result += Task.FIELD_ID + "\":" + this.id + ",\"";
    result += Task.FIELD_GOAL_ID + "\":" + this.goal_id + ",\"";
    result += Task.FIELD_NAME + "\":\"" + this.name + "\",\"";
    result += Task.FIELD_INITIAL + "\":" + df.format(this.initial) + ",\"";
    result += Task.EXTRA_CURRENT + "\":" + df.format(this.current) + ",\"";
    result += Task.EXTRA_TOTAL_TIME_SPENT + "\":" + df.format(this.total_time_spent / 60.0f) + ",\"";
    result += Task.EXTRA_COMPLETION + "\":" + df.format(this.completion * 100.0f) + ",\"";
    result += Task.EXTRA_GOAL_TITLE + "\":\"" + this.goal_title + "\",\"";
    result += Task.FIELD_TARGET + "\":" + this.target + "}";
    return result;
}

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

public void startPayment() {
    /**// www .  ja  v a  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:org.arkanos.aos.api.data.Goal.java

@Override
public String toString() {
    DecimalFormat df = new DecimalFormat();
    df.setMaximumFractionDigits(1);/*from w ww .  java  2s. c o  m*/
    df.setGroupingUsed(false);
    String result = "{\"";
    result += Goal.FIELD_ID + "\":" + this.id + ",\"";
    result += Goal.FIELD_TITLE + "\":\"" + this.title + "\",\"";
    result += Goal.FIELD_TIME_PLANNED + "\":" + df.format(this.time_planned / 60.0f) + ",\"";
    if (this.time_planned > 0) {
        float dedication = (this.total_time_spent * 100.0f) / this.time_planned;
        result += Goal.EXTRA_DEDICATION + "\":" + df.format(dedication) + ",\"";
    }
    result += Goal.EXTRA_TOTAL_TIME_SPENT + "\":" + df.format(this.total_time_spent / 60.0f) + ",\"";
    result += Goal.EXTRA_COMPLETION + "\":" + df.format(this.completion * 100.0f) + ",\"";
    result += Goal.FIELD_DESCRIPTION + "\":\"" + this.description + "\"}";
    return result;
}

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 av  a2 s  .co 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: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//  w  w  w. j  a  v a2 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();
        }

    });

}