Example usage for java.text DecimalFormat setMaximumIntegerDigits

List of usage examples for java.text DecimalFormat setMaximumIntegerDigits

Introduction

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

Prototype

@Override
public void setMaximumIntegerDigits(int newValue) 

Source Link

Document

Sets the maximum number of digits allowed in the integer portion of a number.

Usage

From source file:Main.java

public static DecimalFormat createDecimalFormat(int minInt, int maxInt, int minFract, int maxFract,
        char separator, RoundingMode mode) {

    DecimalFormat format = (DecimalFormat) DecimalFormat.getNumberInstance();
    format.setRoundingMode(mode);/* w  w w . j  ava2s .co m*/

    format.setMaximumFractionDigits(maxFract);
    format.setMinimumFractionDigits(minFract);
    format.setMaximumIntegerDigits(maxInt);
    format.setMinimumIntegerDigits(minInt);
    DecimalFormatSymbols decimalSymbolComma = new DecimalFormatSymbols();
    decimalSymbolComma.setDecimalSeparator(separator);
    format.setDecimalFormatSymbols(decimalSymbolComma);
    format.setGroupingUsed(false);

    return format;
}

From source file:com.mifos.mifosxdroid.adapters.SavingsAccountsListAdapter.java

@SuppressWarnings("deprecation")
@Override//from   w w w  .  j av a2s  . c  o m
public View getView(int i, View view, ViewGroup viewGroup) {

    ReusableViewHolder reusableViewHolder;
    if (view == null) {

        view = layoutInflater.inflate(R.layout.row_account_item, null);
        reusableViewHolder = new ReusableViewHolder(view);
        view.setTag(reusableViewHolder);

    } else {
        reusableViewHolder = (ReusableViewHolder) view.getTag();
    }

    if (savingsAccountList.get(i).getStatus().getActive()) {

        reusableViewHolder.view_status_indicator
                .setBackgroundColor(ContextCompat.getColor(context, R.color.savings_account_status_active));

    } else if (savingsAccountList.get(i).getStatus().getApproved()) {

        reusableViewHolder.view_status_indicator
                .setBackgroundColor(ContextCompat.getColor(context, R.color.status_approved));

    } else if (savingsAccountList.get(i).getStatus().getSubmittedAndPendingApproval()) {

        reusableViewHolder.view_status_indicator.setBackgroundColor(
                ContextCompat.getColor(context, R.color.status_submitted_and_pending_approval));

    } else {
        reusableViewHolder.view_status_indicator
                .setBackgroundColor(ContextCompat.getColor(context, R.color.status_closed));
    }

    Double accountBalance = savingsAccountList.get(i).getAccountBalance();
    DecimalFormat decimalFormat = new DecimalFormat("#.##");
    decimalFormat.setMaximumFractionDigits(2);
    decimalFormat.setMaximumIntegerDigits(10);
    reusableViewHolder.tv_amount
            .setText(String.valueOf(accountBalance == null ? "0.00" : decimalFormat.format(accountBalance)));
    reusableViewHolder.tv_accountNumber.setText(savingsAccountList.get(i).getAccountNo());

    return view;
}

From source file:gov.redhawk.statistics.ui.views.StatisticsView.java

private void updateStatsLabels(int i) {
    int showIndex = i;
    if (datalist.length == 1) {
        showIndex = 0;//w w  w.  j ava2  s  .co m
    }
    Stats s;
    if (showIndex < 0) {
        s = magnitudeStats;
    } else {
        s = stats[showIndex];
    }

    for (int j = 0; j < STAT_PROPS.length; j++) {
        DecimalFormat form;
        double value = s.getStat(STAT_PROPS[j]).doubleValue();
        if (STAT_PROPS[j].equals(Stats.NUM)) {
            form = new DecimalFormat();
        } else if (value != 0 && (Math.abs(value) * 10 < 1 || Math.abs(value) / 10 > 99)) {
            form = new DecimalFormat("0.0#E0");
        } else {
            form = new DecimalFormat();
            form.setMaximumFractionDigits(3);
            form.setMaximumIntegerDigits(2);
        }
        labels[j].setText(form.format(value));
    }
    section.setDescription(getCategoryName(showIndex));
}

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  .j  a  va 2  s . com*/
    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:com.FluksoViz.FluksoVizActivity.java

private String setDecimalFormatProcent(double input_double) {
    // Try Localized numbers and avoid "re-creation" of object
    DecimalFormat df = new DecimalFormat();
    df.setMaximumIntegerDigits(5);
    df.setMaximumFractionDigits(0);//from ww  w.j  a  v  a  2 s  .  com

    if (input_double < 100)
        df.setMaximumIntegerDigits(2);

    if (input_double < 10) {
        df.setMaximumFractionDigits(2);
        df.setMaximumIntegerDigits(1);
    }

    return df.format(input_double);
}

From source file:com.FluksoViz.FluksoVizActivity.java

private String setDecimalFormat(double input_double) {
    // Try Localized numbers and avoid "re-creation" of object
    DecimalFormat df = new DecimalFormat(); // Localized decimal format
    df.setMaximumIntegerDigits(5);
    df.setMaximumFractionDigits(0);/*from  w ww  .jav  a  2s.c om*/

    if (input_double < 1000)
        df.setMaximumIntegerDigits(4);

    if (input_double < 100) {
        df.setMaximumIntegerDigits(3);
        df.setMaximumFractionDigits(2);
    }

    /*
     * Fraction digits set above, if you change this logic remember to set
     * fraction digits here
     */
    if (input_double < 10)
        df.setMaximumIntegerDigits(2);

    return df.format(input_double);
}

From source file:com.eveningoutpost.dexdrip.Home.java

private void handleWordPair() {
    boolean preserve = false;
    if ((thisnumber == -1) || (thisword == ""))
        return;/*from w  w  w  . j a v a2 s  .co m*/

    Log.d(TAG, "GOT WORD PAIR: " + thisnumber + " = " + thisword);

    switch (thisword) {

    case "rapid":
        if ((insulinset == false) && (thisnumber > 0)) {
            thisinsulinnumber = thisnumber;
            textInsulinDose.setText(Double.toString(thisnumber) + " units");
            Log.d(TAG, "Rapid dose: " + Double.toString(thisnumber));
            insulinset = true;
            btnInsulinDose.setVisibility(View.VISIBLE);
            textInsulinDose.setVisibility(View.VISIBLE);
        } else {
            Log.d(TAG, "Rapid dose already set");
            preserve = true;
        }
        break;

    case "carbs":
        if ((carbsset == false) && (thisnumber > 0)) {
            thiscarbsnumber = thisnumber;
            textCarbohydrates.setText(Integer.toString((int) thisnumber) + " carbs");
            carbsset = true;
            Log.d(TAG, "Carbs eaten: " + Double.toString(thisnumber));
            btnCarbohydrates.setVisibility(View.VISIBLE);
            textCarbohydrates.setVisibility(View.VISIBLE);
        } else {
            Log.d(TAG, "Carbs already set");
            preserve = true;
        }
        break;

    case "blood":
        if ((glucoseset == false) && (thisnumber > 0)) {
            thisglucosenumber = thisnumber;
            if (prefs.getString("units", "mgdl").equals("mgdl")) {
                if (textBloodGlucose != null)
                    textBloodGlucose.setText(Double.toString(thisnumber) + " mg/dl");
            } else {
                if (textBloodGlucose != null)
                    textBloodGlucose.setText(Double.toString(thisnumber) + " mmol/l");
            }

            Log.d(TAG, "Blood test: " + Double.toString(thisnumber));
            glucoseset = true;
            if (textBloodGlucose != null) {
                btnBloodGlucose.setVisibility(View.VISIBLE);
                textBloodGlucose.setVisibility(View.VISIBLE);
            }

        } else {
            Log.d(TAG, "Blood glucose already set");
            preserve = true;
        }
        break;

    case "time":
        Log.d(TAG, "processing time keyword");
        if ((timeset == false) && (thisnumber >= 0)) {

            final NumberFormat nf = NumberFormat.getNumberInstance(Locale.US);
            final DecimalFormat df = (DecimalFormat) nf;
            //DecimalFormat df = new DecimalFormat("#");
            df.setMinimumIntegerDigits(2);
            df.setMinimumFractionDigits(2);
            df.setMaximumFractionDigits(2);
            df.setMaximumIntegerDigits(2);

            final Calendar c = Calendar.getInstance();

            final SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("dd/M/yyyy ", Locale.US);
            final SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("dd/M/yyyy HH.mm", Locale.US); // TODO double check 24 hour 12.00 etc
            final String datenew = simpleDateFormat1.format(c.getTime()) + df.format(thisnumber);

            Log.d(TAG, "Time Timing data datenew: " + datenew);

            final Date datethen;
            final Date datenow = new Date();

            try {
                datethen = simpleDateFormat2.parse(datenew);
                double difference = datenow.getTime() - datethen.getTime();
                // is it more than 1 hour in the future? If so it must be yesterday
                if (difference < -(1000 * 60 * 60)) {
                    difference = difference + (86400 * 1000);
                } else {
                    // - midnight feast pre-bolus nom nom
                    if (difference > (60 * 60 * 23 * 1000))
                        difference = difference - (86400 * 1000);
                }

                Log.d(TAG, "Time Timing data: " + df.format(thisnumber) + " = difference ms: "
                        + JoH.qs(difference));
                textTime.setText(df.format(thisnumber));
                timeset = true;
                thistimeoffset = difference;
                btnTime.setVisibility(View.VISIBLE);
                textTime.setVisibility(View.VISIBLE);
            } catch (ParseException e) {
                // toast to explain?
                Log.d(TAG, "Got exception parsing date time");
            }
        } else {
            Log.d(TAG, "Time data already set");
            preserve = true;
        }
        break;
    } // end switch

    if (preserve == false) {
        Log.d(TAG, "Clearing speech values");
        thisnumber = -1;
        thisword = "";
    } else {
        Log.d(TAG, "Preserving speech values");
    }

    // don't show approve/cancel if we only have time
    if (insulinset || glucoseset || carbsset) {
        btnApprove.setVisibility(View.VISIBLE);
        btnCancel.setVisibility(View.VISIBLE);

        if (small_screen) {
            final float button_scale_factor = 0.60f;
            ((ViewGroup.MarginLayoutParams) btnApprove.getLayoutParams()).leftMargin = 0;
            ((ViewGroup.MarginLayoutParams) btnBloodGlucose.getLayoutParams()).leftMargin = 0;
            ((ViewGroup.MarginLayoutParams) btnBloodGlucose.getLayoutParams()).setMarginStart(0);
            ((ViewGroup.MarginLayoutParams) btnCancel.getLayoutParams()).setMarginStart(0);
            ((ViewGroup.MarginLayoutParams) btnApprove.getLayoutParams()).rightMargin = 0;
            ((ViewGroup.MarginLayoutParams) btnCancel.getLayoutParams()).rightMargin = 0;
            btnApprove.setScaleX(button_scale_factor);
            btnApprove.setScaleY(button_scale_factor);
            btnCancel.setScaleX(button_scale_factor);
            btnCancel.setScaleY(button_scale_factor);
            btnInsulinDose.setScaleX(button_scale_factor);
            btnCarbohydrates.setScaleX(button_scale_factor);
            btnCarbohydrates.setScaleY(button_scale_factor);
            btnBloodGlucose.setScaleX(button_scale_factor);
            btnBloodGlucose.setScaleY(button_scale_factor);
            btnInsulinDose.setScaleY(button_scale_factor);
            btnTime.setScaleX(button_scale_factor);
            btnTime.setScaleY(button_scale_factor);

            final int small_text_size = 12;

            textCarbohydrates.setTextSize(small_text_size);
            textInsulinDose.setTextSize(small_text_size);
            textBloodGlucose.setTextSize(small_text_size);
            textTime.setTextSize(small_text_size);

        }

    }

    if (insulinset || glucoseset || carbsset || timeset) {
        if (chart != null) {
            chart.setAlpha((float) 0.10);
        }
        WatchUpdaterService.sendTreatment(thiscarbsnumber, thisinsulinnumber, thisglucosenumber, thistimeoffset,
                textTime.getText().toString());
    }

}