Example usage for java.text NumberFormat setMinimumFractionDigits

List of usage examples for java.text NumberFormat setMinimumFractionDigits

Introduction

In this page you can find the example usage for java.text NumberFormat setMinimumFractionDigits.

Prototype

public void setMinimumFractionDigits(int newValue) 

Source Link

Document

Sets the minimum number of digits allowed in the fraction portion of a number.

Usage

From source file:com.cypress.cysmart.BLEServiceFragments.RSCService.java

/**
 * Display live running data/*from ww  w. jav  a 2 s.  c  o m*/
 */
private void displayLiveData(final ArrayList<String> rsc_data) {
    if (rsc_data != null) {
        try {
            /**
             * Number formatting to two fractional decimals
             */
            Number cycledDist = NumberFormat.getInstance().parse(rsc_data.get(1));
            Number averageSpeed = NumberFormat.getInstance().parse(rsc_data.get(0));
            NumberFormat distformatter = NumberFormat.getNumberInstance();
            distformatter.setMinimumFractionDigits(2);
            distformatter.setMaximumFractionDigits(2);
            String distRan = distformatter.format(cycledDist);
            avgSpeed = distformatter.format(averageSpeed);
            mDistanceRan.setText(distRan);
            mAverageSpeed.setText(avgSpeed);
        } catch (Exception e1) {
            e1.printStackTrace();
        }
        if (mCurrentTime == 0) {
            mGraphLastXValue = 0;
            mCurrentTime = Utils.getTimeInSeconds();
        } else {
            mPreviosTime = mCurrentTime;
            mCurrentTime = Utils.getTimeInSeconds();
            mGraphLastXValue = mGraphLastXValue + (mCurrentTime - mPreviosTime) / 1000;
        }
        try {
            float val = Float.valueOf(avgSpeed);
            mDataSeries.add(mGraphLastXValue, val);
            mChart.repaint();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:org.squale.squaleweb.util.graph.BubbleMaker.java

/**
 * Affichage sous la forme de sous-titres de la rpartition des mthodes - Maintenable et structur, - Maintenable
 * mais mal structur - Difficilement maintenable mais structur - Difficilement maintenable et mal structur
 * /*from  w  ww.jav  a  2  s . c  o  m*/
 * @param pChart graphe de type Bubble
 */
private void displayRepartitionSubtitles(JFreeChart pChart) {
    double percentTopLeft = 0;
    double percentTopRight = 0;
    double percentBottomLeft = 0;
    double percentBottomRight = 0;
    int totalMethods = (int) (totalTopLeft + totalTopRight + totalBottomLeft + totalBottomRight);
    if (totalMethods > 0) {
        final int oneHundred = 100;
        // haut gauche : difficilement maintenable mais structur
        percentTopLeft = totalTopLeft * oneHundred / totalMethods;
        // haut droit : difficilement maintenable et mal structur
        percentTopRight = totalTopRight * oneHundred / totalMethods;
        // Bas gauche : maintenable et structur
        percentBottomLeft = totalBottomLeft * oneHundred / totalMethods;
        // Bas droit : maintenable mais mal structur
        percentBottomRight = totalBottomRight * oneHundred / totalMethods;
    }
    // Formatage des zones d'affichage
    NumberFormat numberFormat = NumberFormat.getInstance();
    numberFormat.setMaximumFractionDigits(1);
    numberFormat.setMinimumFractionDigits(1);
    // Ajout du sous-titre de rpartition des mthodes avec le pourcentage correspondant : partie suprieure, coin
    // gauche et droit
    StringBuffer stringBufferTop = new StringBuffer();
    stringBufferTop.append(WebMessages.getString(locale, "bubble.project.subtitle.topLeft") + " "
            + numberFormat.format(percentTopLeft) + "%     ");
    stringBufferTop.append(WebMessages.getString(locale, "bubble.project.subtitle.topRight") + " "
            + numberFormat.format(percentTopRight) + "%");
    TextTitle subtitleTop = new TextTitle(stringBufferTop.toString());

    // Ajout du sous-titre de rpartition des mthodes avec le pourcentage correspondant : partie infrieure, coin
    // gauche et droit
    StringBuffer stringBufferBottom = new StringBuffer();
    stringBufferBottom.append(WebMessages.getString(locale, "bubble.project.subtitle.bottomLeft") + " "
            + numberFormat.format(percentBottomLeft) + "%     ");
    stringBufferBottom.append(WebMessages.getString(locale, "bubble.project.subtitle.bottomRight") + " "
            + numberFormat.format(percentBottomRight) + "%");
    TextTitle subtitleBottom = new TextTitle(stringBufferBottom.toString());

    // Les rpartitions sont ajoutes sous la forme de sous-menus
    subtitleBottom.setPosition(RectangleEdge.BOTTOM);
    pChart.addSubtitle(subtitleBottom);
    subtitleTop.setPosition(RectangleEdge.BOTTOM);
    pChart.addSubtitle(subtitleTop);
}

From source file:org.totschnig.myexpenses.util.Utils.java

public static String formatCurrency(BigDecimal amount, Currency currency) {
    NumberFormat nf = getNumberFormat();
    int fractionDigits = Money.getFractionDigits(currency);
    nf.setCurrency(currency);/*from ww w.  ja v a2  s .  c om*/
    if (fractionDigits <= 3) {
        nf.setMinimumFractionDigits(fractionDigits);
        nf.setMaximumFractionDigits(fractionDigits);
    } else {
        nf.setMaximumFractionDigits(fractionDigits);
    }
    return nf.format(amount);
}

From source file:com.rockhoppertech.music.Note.java

public String getString() {
    final NumberFormat nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(2);/*ww  w. j  a  v  a  2s  . com*/
    nf.setMinimumFractionDigits(2);
    nf.setMaximumIntegerDigits(3);
    // nf.setMinimumIntegerDigits(3);
    PitchFormat pf = PitchFormat.getInstance();
    return String.format("%s,%s,%s", pf.format(pitch).trim(), nf.format(startBeat),
            DurationParser.getDurationString(duration));
}

From source file:com.rockhoppertech.music.Note.java

/**
 * <code>toString</code>/*from   ww  w. ja va2s  .  c om*/
 * 
 * @return a <code>String</code> value
 */
@Override
public String toString() {
    final StringBuilder sb = new StringBuilder();
    final NumberFormat nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(2);
    nf.setMinimumFractionDigits(2);
    nf.setMaximumIntegerDigits(3);
    nf.setMinimumIntegerDigits(3);
    sb.append(this.getClass().getSimpleName()).append('[');
    sb.append("startBeat: ").append(nf.format(startBeat));
    sb.append(" pitch: ").append(pitch);
    sb.append(" dur: ").append(nf.format(duration));
    sb.append(" : ").append(getDurationString());

    sb.append(" endBeat: ").append(nf.format(endBeat));
    sb.append(" midinum: ").append(pitch.getMidiNumber());
    sb.append(" rest: ").append(rest);
    sb.append(']');
    return sb.toString();
}

From source file:de.xwic.appkit.webbase.table.DefaultColumnLabelProvider.java

private String toString(Object value) {
    String text;//  w  ww .  j a v a  2 s.  c  om

    if (value == null) {
        text = "";
    } else if (value instanceof Date) {
        // special treatment for date objects
        text = dateFormatter.format((Date) value);
    } else if (value instanceof Calendar) {
        Calendar c = (Calendar) value;
        text = dateFormatter.format(c.getTime());
    } else if (value instanceof Long) {
        NumberFormat nf = NumberFormat.getNumberInstance(locale);
        text = nf.format(((Long) value).longValue());
    } else if (value instanceof Double) {
        NumberFormat nf = NumberFormat.getNumberInstance(locale);
        nf.setMinimumFractionDigits(2);
        nf.setMaximumFractionDigits(2);
        text = nf.format(((Double) value).doubleValue());
    } else if (propertyEditor != null) {
        propertyEditor.setValue(value);
        text = propertyEditor.getAsText();
    } else if (value instanceof IPicklistEntry) {
        text = ((IPicklistEntry) value).getBezeichnung(locale.getLanguage());
    } else if (value instanceof IEntity) {
        IEntity entity = (IEntity) value;
        DAO<?> dao = DAOSystem.findDAOforEntity(entity.type());
        text = dao.buildTitle(entity);
    } else if (value instanceof Collection<?>) {
        // set of picklist entries
        StringBuffer sb = new StringBuffer();
        for (Iterator<?> it = ((Collection<?>) value).iterator(); it.hasNext();) {
            Object o = it.next();
            if (sb.length() != 0) {
                sb.append(",");
            }
            sb.append(toString(o));
        }
        text = sb.toString();
    } else if (value instanceof Object[]) {
        StringBuffer sb = new StringBuffer();
        Object[] values = (Object[]) value;
        for (int i = 0; i < values.length; i++) {
            if (sb.length() != 0) {
                sb.append(",");
            }
            sb.append(toString(values[i]));
        }
        text = sb.toString();
    } else {
        text = value.toString();
    }
    return text;

}

From source file:au.org.theark.lims.web.component.biospecimen.batchaliquot.form.BatchAliquotBiospecimenForm.java

public void initialiseForm() {
    numberToCreateTxtFld = new TextField<Number>("numberToCreate",
            new PropertyModel(getModelObject(), "numberToCreate")) {
        /**//from   w  w  w  . ja v  a2  s  .co m
         * 
         */
        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            // Only visible on first instantation of form, once entered and saved, hidden by enclosure
            return getModelObject() == null;
        }
    };

    add(numberToCreateTxtFld);
    add(new AjaxButton("numberToCreateButton") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            if (numberToCreateTxtFld.getDefaultModelObject() != null) {
                int numberToCreate = ((Integer) numberToCreateTxtFld.getDefaultModelObject());
                for (int i = 0; i < numberToCreate; i++) {
                    Biospecimen biospecimen = new Biospecimen();
                    listEditor.addItem(biospecimen);
                    listEditor.updateModel();
                    target.add(form);
                }
            } else {
                error("Please enter a valid number.");
                onError(target, form);
            }
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.add(feedbackPanel);
        }
    });

    add(buildListEditor());

    add(new Label("parentBiospecimen.biospecimenUid",
            new PropertyModel(getModelObject(), "parentBiospecimen.biospecimenUid")));
    parentQtyLbl = new Label("parentBiospecimen.quantity",
            new PropertyModel(getModelObject(), "parentBiospecimen.quantity")) {
        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        @Override
        public <C> IConverter<C> getConverter(Class<C> type) {
            DoubleConverter doubleConverter = new DoubleConverter();
            NumberFormat numberFormat = NumberFormat.getInstance();
            numberFormat.setMinimumFractionDigits(1);
            doubleConverter.setNumberFormat(getLocale(), numberFormat);
            return (IConverter<C>) doubleConverter;
        }
    };
    add(parentQtyLbl);
    add(new Label("parentBiospecimen.unit.name",
            new PropertyModel(getModelObject(), "parentBiospecimen.unit.name")));

    add(new AjaxEditorButton(Constants.NEW) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.add(feedbackPanel);
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            Biospecimen biospecimen = new Biospecimen();
            copyBiospecimen = false;
            listEditor.addItem(biospecimen);
            target.add(form);
        }
    }.setDefaultFormProcessing(false));

    add(new AjaxButton(Constants.SAVE) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            onSave(target);
            target.add(feedbackPanel);
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.add(feedbackPanel);
        }

        @Override
        public boolean isVisible() {
            return false;
        }
    });

    add(new AjaxButton(Constants.SAVEANDCLOSE) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            if (onSave(target)) {
                modalWindow.close(target);
            }
            target.add(feedbackPanel);
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.add(feedbackPanel);
        }
    });

    add(new AjaxButton(Constants.CANCEL) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            modalWindow.close(target);
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.add(feedbackPanel);
        }
    }.setDefaultFormProcessing(false));
}

From source file:au.org.theark.lims.web.component.biospecimen.batchcreate.form.AutoGenBatchCreateBiospecimenForm.java

/**
 * //from www.  ja  va2 s. co  m
 * @return the listEditor of BatchBiospecimen(s)
 */
public AbstractListEditor<BatchBiospecimenVO> buildListEditor() {
    listEditor = new AbstractListEditor<BatchBiospecimenVO>("batchBiospecimenList",
            new PropertyModel(this, "batchBiospecimenList")) {

        private static final long serialVersionUID = 1L;

        @SuppressWarnings("serial")
        @Override
        protected void onPopulateItem(final ListItem<BatchBiospecimenVO> item) {
            item.setOutputMarkupId(true);
            item.getModelObject().getBiospecimen()
                    .setLinkSubjectStudy(cpModel.getObject().getLinkSubjectStudy());
            item.getModelObject().getBiospecimen()
                    .setStudy(cpModel.getObject().getLinkSubjectStudy().getStudy());

            numberToCreateTxtFld = new TextField<Number>("numberToCreate",
                    new PropertyModel(item.getModelObject(), "numberToCreate"));

            initBioCollectionDdc(item);
            initSampleTypeDdc(item);

            sampleDateTxtFld = new DateTextField("biospecimen.sampleDate",
                    new PropertyModel(item.getModelObject(), "biospecimen.sampleDate"),
                    au.org.theark.core.Constants.DD_MM_YYYY);
            ArkDatePicker sampleDatePicker = new ArkDatePicker();
            sampleDatePicker.bind(sampleDateTxtFld);
            sampleDateTxtFld.add(sampleDatePicker);

            quantityTxtFld = new TextField<Double>("biospecimen.quantity",
                    new PropertyModel(item.getModelObject(), "biospecimen.quantity")) {
                private static final long serialVersionUID = 1L;

                @Override
                public <C> IConverter<C> getConverter(Class<C> type) {
                    DoubleConverter doubleConverter = new DoubleConverter();
                    NumberFormat numberFormat = NumberFormat.getInstance();
                    numberFormat.setMinimumFractionDigits(1);
                    doubleConverter.setNumberFormat(getLocale(), numberFormat);
                    return (IConverter<C>) doubleConverter;
                }
            };
            initUnitDdc(item);
            initTreatmentTypeDdc(item);
            concentrationTxtFld = new TextField<Number>("biospecimen.concentration",
                    new PropertyModel(item.getModelObject(), "biospecimen.concentration"));

            // Added onchange events to ensure model updated when any change made
            item.add(numberToCreateTxtFld.add(new AjaxFormComponentUpdatingBehavior("onchange") {
                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                }
            }));
            item.add(bioCollectionDdc.add(new AjaxFormComponentUpdatingBehavior("onchange") {
                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                }
            }));
            item.add(sampleTypeDdc.add(new AjaxFormComponentUpdatingBehavior("onchange") {
                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                }
            }));
            item.add(sampleDateTxtFld.add(new AjaxFormComponentUpdatingBehavior("onchange") {
                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                }
            }));
            item.add(quantityTxtFld.add(new AjaxFormComponentUpdatingBehavior("onchange") {
                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                }
            }));
            item.add(unitDdc.add(new AjaxFormComponentUpdatingBehavior("onchange") {
                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                }
            }));
            item.add(treatmentTypeDdc.add(new AjaxFormComponentUpdatingBehavior("onchange") {
                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                }
            }));
            item.add(concentrationTxtFld.add(new AjaxFormComponentUpdatingBehavior("onchange") {
                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                }
            }));

            // Copy button allows entire row details to be copied
            item.add(new AjaxEditorButton(Constants.COPY) {
                private static final long serialVersionUID = 1L;

                @Override
                protected void onError(AjaxRequestTarget target, Form<?> form) {
                    target.add(feedbackPanel);
                }

                @Override
                protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                    BatchBiospecimenVO batchBiospecimenVo = new BatchBiospecimenVO();
                    try {
                        batchBiospecimenVo.setNumberToCreate(item.getModelObject().getNumberToCreate());
                        PropertyUtils.copyProperties(batchBiospecimenVo.getBiospecimen(),
                                item.getModelObject().getBiospecimen());
                        listEditor.addItem(batchBiospecimenVo);
                        target.add(form);
                    } catch (IllegalAccessException e) {
                        e.printStackTrace();
                    } catch (InvocationTargetException e) {
                        e.printStackTrace();
                    } catch (NoSuchMethodException e) {
                        e.printStackTrace();
                    }
                }
            }.setDefaultFormProcessing(false));

            item.add(new AjaxEditorButton(Constants.DELETE) {
                private static final long serialVersionUID = 1L;

                @Override
                protected void onError(AjaxRequestTarget target, Form<?> form) {
                    target.add(feedbackPanel);
                }

                @Override
                protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                    listEditor.removeItem(item);
                    target.add(form);
                }
            }.setDefaultFormProcessing(false).setVisible(item.getIndex() > 0));

            item.add(new AttributeModifier(Constants.CLASS, new AbstractReadOnlyModel() {

                private static final long serialVersionUID = 1L;

                @Override
                public String getObject() {
                    return (item.getIndex() % 2 == 1) ? Constants.EVEN : Constants.ODD;
                }
            }));
        }

    };
    return listEditor;
}

From source file:org.moqui.impl.context.L10nFacadeImpl.java

@Override
public String formatCurrency(Object amount, String uomId, Integer fractionDigits, Locale locale) {
    if (amount == null)
        return "";
    if (amount instanceof CharSequence) {
        if (((CharSequence) amount).length() == 0) {
            return "";
        } else {// w  ww  .  j  ava 2s .  c  om
            amount = parseNumber((String) amount, null);
        }
    }

    if (locale == null)
        locale = getLocale();
    NumberFormat nf = NumberFormat.getCurrencyInstance(locale);
    Currency currency = uomId != null && uomId.length() > 0 ? Currency.getInstance(uomId) : null;
    if (currency != null)
        nf.setCurrency(currency);
    if (fractionDigits == null)
        fractionDigits = currency != null ? currency.getDefaultFractionDigits() : 2;
    nf.setMaximumFractionDigits(fractionDigits);
    nf.setMinimumFractionDigits(fractionDigits);
    return nf.format(amount);
}

From source file:com.nubits.nubot.trading.wrappers.BitcoinCoIDWrapper.java

private ApiResponse enterOrder(String type, CurrencyPair pair, double amount, double price) {
    ApiResponse apiResponse = new ApiResponse();
    String url = API_BASE_URL;
    String method = API_TRADE;//from w w w .java  2s. c  o  m
    HashMap<String, String> args = new HashMap<>();
    boolean isGet = false;
    String order_id = null;

    args.put("pair", pair.toStringSep());
    args.put("type", type.toLowerCase());
    NumberFormat nf = NumberFormat.getInstance();
    nf.setMinimumFractionDigits(8);
    args.put("price", nf.format(price));
    if (type.equals(Constant.SELL)) {
        args.put(pair.getPaymentCurrency().getCode().toLowerCase(), nf.format(amount * price));
        args.put(pair.getOrderCurrency().getCode().toLowerCase(), nf.format(amount));
    } else {
        args.put(pair.getPaymentCurrency().getCode().toLowerCase(), nf.format(amount * price));
    }

    ApiResponse response = getQuery(url, method, args, true, isGet);
    if (response.isPositive()) {
        JSONObject httpAnswerJson = (JSONObject) response.getResponseObject();
        JSONObject data = (JSONObject) httpAnswerJson.get("return");
        order_id = data.get("order_id").toString();
        apiResponse.setResponseObject(order_id);
    } else {
        apiResponse = response;
    }
    return apiResponse;
}