Example usage for java.text NumberFormat format

List of usage examples for java.text NumberFormat format

Introduction

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

Prototype

public final String format(long number) 

Source Link

Document

Specialization of format.

Usage

From source file:com.prowidesoftware.swift.model.field.Field37U.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8//w ww . jav a2s. c  o  m
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 1) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 37U");
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    if (component == 1) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent1AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    return null;
}

From source file:com.formkiq.core.equifax.service.EquifaxResponseProcessor.java

/**
 * Process SCOR segment and update Response.
 * @param scorSegment {@link ScorSegment}
 * @param form {@link FormJSON}/*from w ww.  ja  v  a2  s  . c  om*/
 * @return {@link String} error message
 */
private Map<String, List<FormJSONValidator>> processScorSegment(final ScorSegment scorSegment,
        final FormJSON form) {

    final int group = 3;
    Map<String, List<FormJSONValidator>> map = new HashMap<>();

    String narrative = scorSegment.getDecisionNarrative();
    Matcher matcher = UNDER_PATTERN.matcher(narrative);

    if (matcher.matches()) {

        try {

            String s = matcher.group(group).trim();
            String[] strs = s.split("[ \\$]");

            int max = Integer.parseInt(strs[1]);
            FormJSONValidator v1 = new FormJSONValidator();
            v1.setRule(FormJSONValidatorRuleType.MAX);
            v1.setValue(strs[1]);
            v1.setMessage("Approved for a maximum of $" + this.formatter.format(max));

            FormJSONValidator v2 = new FormJSONValidator();
            v2.setRule(FormJSONValidatorRuleType.MESSAGE);
            v2.setMessage("Approved for a maximum of $" + this.formatter.format(max));

            // SubTotal
            // TODO remove & change to something that can be references by
            // other forms
            map.put("$st", Arrays.asList(v1));
            map.put("*", Arrays.asList(v2));

            Locale locale = new Locale("en", "US");
            NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(locale);

            String money = currencyFormatter.format(max);
            if (money.endsWith(".00")) {
                int centsIndex = money.lastIndexOf(".00");
                if (centsIndex != -1) {
                    money = money.substring(1, centsIndex);
                }
            }

            findValueByKey(form, "approvedamount").get().setValue(money);

        } catch (NumberFormatException e) {

            addValidation(map, FormJSONValidatorRuleType.STOP,
                    "Unable to process Equifax Request. " + "Please try again later.");
        }

    } else {

        addValidation(map, FormJSONValidatorRuleType.STOP, "Application is not approved");
    }

    return map;
}

From source file:com.celements.web.service.CelementsWebScriptService.java

public String getHumanReadableSize(long bytes, boolean si, Locale locale) {
    int unit = si ? 1000 : 1024;
    if (bytes < unit) {
        return bytes + " B";
    }/*from  w  w  w .ja  va 2  s. c  o  m*/
    int exp = (int) (Math.log(bytes) / Math.log(unit));
    String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (si ? "" : "i");
    NumberFormat decimalFormat = DecimalFormat.getInstance(locale);
    decimalFormat.setMaximumFractionDigits(1);
    decimalFormat.setMinimumFractionDigits(1);
    return String.format("%s %sB", decimalFormat.format(bytes / Math.pow(unit, exp)), pre);
}

From source file:com.prowidesoftware.swift.model.field.Field19.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8//from  ww w  .  j a v  a  2 s  .co m
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 1) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 19");
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    if (component == 1) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent1AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    return null;
}

From source file:fr.ign.cogit.geoxygene.appli.layer.LayerViewAwtPanel.java

private void saveImage() {
    LayerViewAwtPanel.logger.debug("record"); //$NON-NLS-1$
    Color bg = this.getBackground();
    BufferedImage image = new BufferedImage(this.getWidth(), this.getHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics = image.createGraphics();
    graphics.setColor(bg);/* w ww  .j  a  v a  2  s  .c o  m*/
    graphics.fillRect(0, 0, this.getWidth(), this.getHeight());
    this.getRenderingManager().copyTo(graphics);
    this.recording = false;
    // this.paintOverlays(graphics);
    graphics.dispose();
    try {
        NumberFormat format = NumberFormat.getInstance();
        format.setMinimumIntegerDigits(3);
        ImgUtil.saveImage(image, this.recordFileName + format.format(this.recordIndex) + ".png"); //$NON-NLS-1$
        this.recordIndex++;
    } catch (IOException e1) {
        e1.printStackTrace();
    }
}

From source file:com.salesmanager.core.module.impl.application.currencies.GenericCurrencyModule.java

public String getFormatedAmount(BigDecimal amount) throws Exception {
    // TODO Auto-generated method stub
    NumberFormat nf = null;

    Locale locale = Locale.US;

    if (this.decimalPoint == ',') {
        locale = Locale.GERMAN;//w  w  w . ja va 2s . c  o  m
    }

    nf = NumberFormat.getInstance(locale);

    nf.setMaximumFractionDigits(Integer.parseInt(Character.toString(decimalCount)));
    nf.setMinimumFractionDigits(Integer.parseInt(Character.toString(decimalCount)));

    return nf.format(amount);
}

From source file:com.prowidesoftware.swift.model.field.Field129.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8/*from  ww w . j  av a 2s.c  om*/
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 2) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 129");
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    if (component == 1) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent1AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    if (component == 2) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent2AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    return null;
}

From source file:com.prowidesoftware.swift.model.field.Field27.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8//from  w  ww  .j av  a2  s .  c  o  m
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 2) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 27");
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    if (component == 1) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent1AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    if (component == 2) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent2AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    return null;
}

From source file:com.prowidesoftware.swift.model.field.Field27A.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8//  ww  w.  j a  v a  2s.  co  m
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 2) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 27A");
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    if (component == 1) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent1AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    if (component == 2) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent2AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    return null;
}

From source file:com.prowidesoftware.swift.model.field.Field39A.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8//  w  ww  .j  a  v  a  2s .c  o  m
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 2) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 39A");
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    if (component == 1) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent1AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    if (component == 2) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent2AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    return null;
}