List of usage examples for java.text NumberFormat format
public final String format(long number)
From source file:com.commander4j.util.JUtility.java
public static String bigDecimaltoString(BigDecimal bd) { String result = ""; NumberFormat nf1 = NumberFormat.getInstance(); nf1 = NumberFormat.getInstance(); nf1.setMinimumFractionDigits(3);/*from ww w . j a v a 2 s . c o m*/ nf1.setMaximumFractionDigits(3); result = nf1.format(bd); return result; }
From source file:com.prowidesoftware.swift.model.field.Field19C.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// www . j ava 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 19C"); } if (locale == null) { locale = Locale.getDefault(); } if (component == 1) { //default format (as is) return getComponent(1); } 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.Field37G.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 w w.ja va2 s.com */ @Override public String getValueDisplay(int component, Locale locale) { if (component < 1 || component > 2) { throw new IllegalArgumentException("invalid component number " + component + " for field 37G"); } if (locale == null) { locale = Locale.getDefault(); } if (component == 1) { //default format (as is) return getComponent(1); } 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.Field37M.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 .ja v 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 37M"); } if (locale == null) { locale = Locale.getDefault(); } if (component == 1) { //default format (as is) return getComponent(1); } 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.Field37R.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 av a 2 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 37R"); } if (locale == null) { locale = Locale.getDefault(); } if (component == 1) { //default format (as is) return getComponent(1); } 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.Field37V.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 .jav 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 37V"); } if (locale == null) { locale = Locale.getDefault(); } if (component == 1) { //default format (as is) return getComponent(1); } 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:javadz.beanutils.converters.NumberConverter.java
/** * Convert an input Number object into a String. * * @param value The input value to be converted * @return the converted String value./*from w w w . j av a 2 s . c o m*/ * @throws Throwable if an error occurs converting to a String */ protected String convertToString(Object value) throws Throwable { String result = null; if (useLocaleFormat && value instanceof Number) { NumberFormat format = getFormat(); format.setGroupingUsed(false); result = format.format(value); if (log().isDebugEnabled()) { log().debug(" Converted to String using format '" + result + "'"); } } else { result = value.toString(); if (log().isDebugEnabled()) { log().debug(" Converted to String using toString() '" + result + "'"); } } return result; }
From source file:com.prowidesoftware.swift.model.field.Field62A.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 . java 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 62A"); } if (locale == null) { locale = Locale.getDefault(); } if (component == 1) { //default format (as is) return getComponent(1); } 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.Field62B.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 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 62B"); } if (locale == null) { locale = Locale.getDefault(); } if (component == 1) { //default format (as is) return getComponent(1); } 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.Field37S.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 www. j a v a2s . c om */ @Override public String getValueDisplay(int component, Locale locale) { if (component < 1 || component > 2) { throw new IllegalArgumentException("invalid component number " + component + " for field 37S"); } 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; }