本文整理汇总了Java中com.ibm.icu.text.NumberFormat.format方法的典型用法代码示例。如果您正苦于以下问题:Java NumberFormat.format方法的具体用法?Java NumberFormat.format怎么用?Java NumberFormat.format使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.ibm.icu.text.NumberFormat
的用法示例。
在下文中一共展示了NumberFormat.format方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: normalizeDouble
import com.ibm.icu.text.NumberFormat; //导入方法依赖的package包/类
/**
* Normalize double value to avoid error precision.
*
* @param value
* @return normalized value of specified double.
*/
public static Number normalizeDouble( Double value )
{
if ( value.isNaN( ) )
{
return 0;
}
NumberFormat df = createDefaultNumberFormat( value, ULocale.ENGLISH );
// Normalize double value to avoid double precision error.
String sValue = df.format( value );
try
{
return df.parse( sValue );
}
catch ( ParseException e )
{
logger.log( e );
}
return value;
}
示例2: getDefaultSymbolPosition
import com.ibm.icu.text.NumberFormat; //导入方法依赖的package包/类
/**
* Returns the default percent symbol position for given locale
*
* @param locale
* @return
*/
public static String getDefaultSymbolPosition( ULocale locale )
{
if ( locale == null )
{
locale = ULocale.getDefault( );
}
NumberFormat formater = NumberFormat.getPercentInstance( locale );
String result = formater.format( 1 );
if ( result.endsWith( "%" ) ) //$NON-NLS-1$
{
return FormatNumberPattern.SYMBOL_POSITION_AFTER;
}
else
{
return FormatNumberPattern.SYMBOL_POSITION_BEFORE;
}
}
示例3: toFixedDecimal
import com.ibm.icu.text.NumberFormat; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
com.ibm.icu.text.PluralRules.FixedDecimal toFixedDecimal(double n) {
NumberFormat nf = getNumberFormat();
StringBuffer sb = new StringBuffer();
FieldPosition fp = new FieldPosition(DecimalFormat.FRACTION_FIELD);
nf.format(n, sb, fp);
int v = fp.getEndIndex() - fp.getBeginIndex();
long f = 0;
if (v > 0) {
ParsePosition pp = new ParsePosition(fp.getBeginIndex());
f = nf.parse(sb.toString(), pp).longValue();
}
return new com.ibm.icu.text.PluralRules.FixedDecimal(n, v, f);
}
示例4: getDefaultSymbolPosition
import com.ibm.icu.text.NumberFormat; //导入方法依赖的package包/类
/**
* Returns the default currency symbol position for given locale. Returns
* <code>null</code> if no symbol needed by default.
*
* @param locale
* @return
*/
public static String getDefaultSymbolPosition( ULocale locale )
{
if ( locale == null )
{
locale = ULocale.getDefault( );
}
Currency currency = Currency.getInstance( locale );
if ( currency != null )
{
String symbol = currency.getSymbol( );
if ( symbol == null )
{
return null;
}
NumberFormat formater = NumberFormat.getCurrencyInstance( locale );
String result = formater.format( 1 );
if ( result.endsWith( symbol ) )
{
return FormatNumberPattern.SYMBOL_POSITION_AFTER;
}
else
{
return FormatNumberPattern.SYMBOL_POSITION_BEFORE;
}
}
return null;
}
示例5: getDefaultUsingSymbolSpace
import com.ibm.icu.text.NumberFormat; //导入方法依赖的package包/类
/**
* Returns the if symbol space is used by default for given locale.
*
* @param locale
* @return
*/
public static boolean getDefaultUsingSymbolSpace( ULocale locale )
{
if ( locale == null )
{
locale = ULocale.getDefault( );
}
Currency currency = Currency.getInstance( locale );
if ( currency != null )
{
String symbol = currency.getSymbol( );
if ( symbol == null )
{
return false;
}
NumberFormat formater = NumberFormat.getCurrencyInstance( locale );
String result = formater.format( 1 );
if ( result.endsWith( symbol ) )
{
result = result.substring( 0, result.indexOf( symbol ) );
for ( int i = result.length( ) - 1; i >= 0; i-- )
{
if ( UCharacter.isSpaceChar( result.codePointAt( i ) ) )
{
return true;
}
}
}
else
{
result = result.substring( result.indexOf( symbol )
+ symbol.length( ) );
for ( int i = 0; i < result.length( ); i++ )
{
if ( UCharacter.isSpaceChar( result.codePointAt( i ) ) )
{
return true;
}
}
}
}
return false;
}
示例6: formatNumber
import com.ibm.icu.text.NumberFormat; //导入方法依赖的package包/类
public String formatNumber(final Number n, final LotusNumberOptions lno) {
NumberFormat nf;
/*
* It would have been more convenient to use NumberFormat.getInstance(locale, style),
* but this method is private in com.ibm.icu_3.8.1.v20120530.jar.
* (Seems to be public as of ICU 4.2.)
*/
if (lno.format == 'C')
nf = NumberFormat.getCurrencyInstance(iLocale);
else if (lno.format == 'S')
nf = NumberFormat.getScientificInstance(iLocale);
else if (lno.format == '%')
nf = NumberFormat.getPercentInstance(iLocale);
else
nf = NumberFormat.getNumberInstance(iLocale);
nf.setGroupingUsed(lno.useGrouping);
nf.setMaximumIntegerDigits(1000);
if (lno.fractionDigits != -1) {
nf.setMinimumFractionDigits(lno.fractionDigits);
nf.setMaximumFractionDigits(lno.fractionDigits);
} else
nf.setMaximumFractionDigits(1000);
String ret = nf.format(n);
do {
if (lno.format != 'G' || ret.length() <= 15)
break;
/*
* In this case, Lotus implicitly switches to scientific style.
* When useGrouping is in effect, the limit decreases from 15 to 12 in Lotus
* (i.e. the grouping bytes are likewise counted), but we are not going to
* imitate this strange behaviour.
*/
String tester = ret;
if (lno.useGrouping) {
nf.setGroupingUsed(false);
tester = nf.format(n);
}
int minus = (tester.charAt(0) == '-') ? 1 : 0;
int lh = tester.length();
if (lh - minus <= 15)
break;
int komma = minus;
for (; komma < lh; komma++)
if (!Character.isDigit(tester.charAt(komma)))
break;
if (komma - minus <= 15)
break;
nf = NumberFormat.getScientificInstance(iLocale);
nf.setGroupingUsed(lno.useGrouping);
ret = nf.format(n);
} while (false);
if (lno.negativeAsParentheses && ret.charAt(0) == '-')
ret = '(' + ret.substring(1) + ')';
return ret;
}
示例7: formatNumber
import com.ibm.icu.text.NumberFormat; //导入方法依赖的package包/类
/**
* Use default number format pattern to format number value. If value < 1
* then at most remains 3 significant figures but the total decimal digits
* can't exceed 9, else use default format instance of system to format
* number.
*
* @param value
* @param locale
* @return
*/
private static final String formatNumber( Number value, ULocale locale )
{
NumberFormat format = createDefaultNumberFormat( value, locale );
return format.format( value );
}