当前位置: 首页>>代码示例>>Java>>正文


Java NumberFormat类代码示例

本文整理汇总了Java中com.ibm.icu.text.NumberFormat的典型用法代码示例。如果您正苦于以下问题:Java NumberFormat类的具体用法?Java NumberFormat怎么用?Java NumberFormat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


NumberFormat类属于com.ibm.icu.text包,在下文中一共展示了NumberFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: style

import com.ibm.icu.text.NumberFormat; //导入依赖的package包/类
@Override
public PatternNode style(java.lang.String argumentName) {
    Function<Locale, NumberFormat> formatFactory = Opt(() -> {
        Str(",");
        whiteSpace();
        Function<Locale, NumberFormat> result = this
                .<Function<Locale, NumberFormat>> FirstOf(() -> {
            Str("integer");
            return l -> NumberFormat.getIntegerInstance(l);
        } , () -> {
            Str("currency");
            return l -> NumberFormat.getCurrencyInstance(l);
        } , () -> {
            Str("percent");
            return l -> NumberFormat.getPercentInstance(l);
        } , () -> {
            String pattern = subFormatPattern();
            return l -> new DecimalFormat(pattern,
                    DecimalFormatSymbols.getInstance(l));
        });
        whiteSpace();
        return result;
    }).orElse(l -> NumberFormat.getInstance(l));
    return new FormatNode(argumentName, formatFactory);
}
 
开发者ID:ruediste,项目名称:i18n,代码行数:26,代码来源:NumberParser.java

示例2: check

import com.ibm.icu.text.NumberFormat; //导入依赖的package包/类
@Override
public void check(Placeholder target, ULocale locale, String message) throws AssertionError {
  String pattern = target.getPattern();
  String skeleton = target.getSkeleton();
  String value = target.getExpectedValue();
  Number expected = null;

  if (value != null) {
      try {
        expected = NumberFormat.getInstance().parse(value);
      } catch (ParseException e) {
        throw new AssertionError(
            String.format("The \"%s\" is an invalid value parameter for the date time checkers. "
              + "Please specify numeric representation of date (see Date.getTime())", value));
      }
  }
  if (pattern != null) {
    makePatternBasedCheck(target, pattern, locale, expected);
  } else if (skeleton != null) {
    DateTimePatternGenerator patternGenerator = DateTimePatternGenerator.getInstance(locale);
    pattern = patternGenerator.getBestPattern(skeleton);
    makePatternBasedCheck(target, pattern, locale, expected);
  } else {
    makeDateTimeCheck(target, locale, expected);
  }
}
 
开发者ID:googlei18n,项目名称:i18n_sanitycheck,代码行数:27,代码来源:TimeDateChecker.java

示例3: getTypedDataElement

import com.ibm.icu.text.NumberFormat; //导入依赖的package包/类
private double getTypedDataElement( String strDataElement )
{
	if ( strDataElement.trim( ).length( ) == 0 )
	{
		return 0.0;
	}
	NumberFormat nf = ChartUIUtil.getDefaultNumberFormatInstance( );

	try
	{
		Number numberElement = nf.parse( strDataElement );
		return numberElement.doubleValue( );
	}
	catch ( ParseException e1 )
	{
		return 0.0;
	}
}
 
开发者ID:eclipse,项目名称:birt,代码行数:19,代码来源:RadarLineSheet.java

示例4: getDataElement

import com.ibm.icu.text.NumberFormat; //导入依赖的package包/类
public DataElement getDataElement( )
{
	NumberFormat nf = ChartUIUtil.getDefaultNumberFormatInstance( );
	try
	{
		Number number = nf.parse( getText( ) );
		if (number instanceof BigInteger)
		{
			BigInteger biNumber = (BigInteger)number;
			return BigNumberDataElementImpl.create( new BigDecimal( biNumber ).stripTrailingZeros( ) );
		}
		return NumberDataElementImpl.create( number.doubleValue( ) );
	}
	catch ( ParseException e1 )
	{
		return null;
	}
}
 
开发者ID:eclipse,项目名称:birt,代码行数:19,代码来源:NumberDataElementComposite.java

示例5: getTypedDataElement

import com.ibm.icu.text.NumberFormat; //导入依赖的package包/类
private DataElement getTypedDataElement( String strDataElement )
{
	if ( strDataElement == null )
	{
		return null;
	}
	if ( strDataElement.trim( ).length( ) == 0 )
	{
		return NumberDataElementImpl.create( 0.0 );
	}
	NumberFormat nf = ChartUIUtil.getDefaultNumberFormatInstance( );

	try
	{
		Number numberElement = nf.parse( strDataElement );
		return NumberDataElementImpl.create( numberElement.doubleValue( ) );
	}
	catch ( ParseException e1 )
	{
		return NumberDataElementImpl.create( 0.0 );
	}
}
 
开发者ID:eclipse,项目名称:birt,代码行数:23,代码来源:SeriesRegionSheet.java

示例6: 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;
}
 
开发者ID:eclipse,项目名称:birt,代码行数:29,代码来源:ValueFormatter.java

示例7: stringToInt

import com.ibm.icu.text.NumberFormat; //导入依赖的package包/类
/**
 * Transform a String value to an int value
 *
 * @param stringValue
 *            String value
 * @return Corresponding int value
 */
private int stringToInt(String stringValue) {
	if (stringValue != null) {
		try {
			//xls is returning doubles 
			return (int)Double.parseDouble(stringValue);
		} catch (NumberFormatException e) {
			try {
				Number number = NumberFormat
						.getInstance(JRE_DEFAULT_LOCALE).parse(stringValue);
				if (number != null) {
					return number.intValue();
				}
			} catch (ParseException e1) {
			}
		}
	}
	this.wasNull = true;
	return 0;
}
 
开发者ID:eclipse,项目名称:birt,代码行数:27,代码来源:ResultSet.java

示例8: stringToDouble

import com.ibm.icu.text.NumberFormat; //导入依赖的package包/类
/**
 * Transform a String value to a double value
 *
 * @param stringValue
 *            String value
 * @return Corresponding double value
 */
private double stringToDouble(String stringValue) {
	if (stringValue != null) {
		try {
			return Double.parseDouble(stringValue);
		} catch (NumberFormatException e) {
			try {
				Number number = NumberFormat
						.getInstance(JRE_DEFAULT_LOCALE).parse(stringValue);
				if (number != null) {
					return number.doubleValue();
				}
			} catch (ParseException e1) {
			}
		}
	}
	this.wasNull = true;
	return 0;
}
 
开发者ID:eclipse,项目名称:birt,代码行数:26,代码来源:ResultSet.java

示例9: stringToBigDecimal

import com.ibm.icu.text.NumberFormat; //导入依赖的package包/类
/**
 * Transform a String value to a big decimal value
 *
 * @param stringValue
 *            String value
 * @return Corresponding BigDecimal value
 */
private BigDecimal stringToBigDecimal(String stringValue) {
	if (stringValue != null) {
		try {
			return new BigDecimal(stringValue);
		} catch (NumberFormatException e) {
			try {
				Number number = NumberFormat
						.getInstance(JRE_DEFAULT_LOCALE).parse(stringValue);
				if (number != null) {
					return new BigDecimal(number.toString());
				}
			} catch (ParseException e1) {
			}
		}
	}
	this.wasNull = true;
	return null;
}
 
开发者ID:eclipse,项目名称:birt,代码行数:26,代码来源:ResultSet.java

示例10: toBigDecimalFromString

import com.ibm.icu.text.NumberFormat; //导入依赖的package包/类
public static BigDecimal toBigDecimalFromString( String s ) throws OdaException
{
	if ( s == null )
	{
		return null;
	}
	try
	{
		Number n = NumberFormat.getInstance( locale ).parse( s );
		return new BigDecimal( n.toString( ) );
	}
	catch ( ParseException e )
	{
		throw new OdaException( e );
	}
}
 
开发者ID:eclipse,项目名称:birt,代码行数:17,代码来源:DataTypeUtil.java

示例11: getCurrencySymbol

import com.ibm.icu.text.NumberFormat; //导入依赖的package包/类
private static String getCurrencySymbol( ULocale locale )
{
	NumberFormat format = NumberFormat.getCurrencyInstance( locale );
	Currency currency = format.getCurrency( );
	if ( currency != null )
	{
		String symbol = currency.getSymbol( locale );
		if ( symbol.equals( "EUR" ) )
		{
			symbol = "\u20ac"; // "€";
		}
		else if ( symbol.equals( "GBP" ) )
		{
			symbol = "\u00a3"; // "£";
		}
		else if ( symbol.equals( "XXX" ) )
		{
			symbol = "\u00a4"; // "¤";
		}
		return symbol;
	}
	return "$";
}
 
开发者ID:eclipse,项目名称:birt,代码行数:24,代码来源:ExcelUtil.java

示例12: 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;
	}
}
 
开发者ID:eclipse,项目名称:birt,代码行数:25,代码来源:FormatPercentNumPattern.java

示例13: isValidNumber

import com.ibm.icu.text.NumberFormat; //导入依赖的package包/类
private boolean isValidNumber( String text )
{
	ULocale locale = getLocaleByDisplayName( localeChoicer.getText( ) );
	if ( locale == null )
	{
		locale = ULocale.getDefault( );
	}

	try
	{
		NumberFormat.getNumberInstance( locale ).parse( text );
		return true;
	}
	catch ( ParseException e )
	{
	}
	return false;
}
 
开发者ID:eclipse,项目名称:birt,代码行数:19,代码来源:FormatNumberLayoutPeer.java

示例14: createNumberFormat

import com.ibm.icu.text.NumberFormat; //导入依赖的package包/类
private NumberFormat createNumberFormat() {
    ULocale locale = ULocale.forLanguageTag(this.locale);
    locale = locale.setKeywordValue("numbers", "latn");

    DecimalFormat numberFormat = (DecimalFormat) NumberFormat.getInstance(locale, NumberFormat.NUMBERSTYLE);
    if (minimumSignificantDigits != 0 && maximumSignificantDigits != 0) {
        numberFormat.setSignificantDigitsUsed(true);
        numberFormat.setMinimumSignificantDigits(minimumSignificantDigits);
        numberFormat.setMaximumSignificantDigits(maximumSignificantDigits);
    } else {
        numberFormat.setSignificantDigitsUsed(false);
        numberFormat.setMinimumIntegerDigits(minimumIntegerDigits);
        numberFormat.setMinimumFractionDigits(minimumFractionDigits);
        numberFormat.setMaximumFractionDigits(maximumFractionDigits);
    }
    // as required by ToRawPrecision/ToRawFixed
    numberFormat.setRoundingMode(BigDecimal.ROUND_HALF_UP);
    return numberFormat;
}
 
开发者ID:anba,项目名称:es6draft,代码行数:20,代码来源:PluralRulesObject.java

示例15: 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);
}
 
开发者ID:anba,项目名称:es6draft,代码行数:17,代码来源:PluralRulesObject.java


注:本文中的com.ibm.icu.text.NumberFormat类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。