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


Java DecimalFormatSymbols类代码示例

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


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

示例1: getInstance

import java.text.DecimalFormatSymbols; //导入依赖的package包/类
private NumberFormat getInstance(Locale locale,
                                        int choice) {
    if (locale == null) {
        throw new NullPointerException();
    }

    LocaleProviderAdapter adapter = LocaleProviderAdapter.forType(type);
    String[] numberPatterns = adapter.getLocaleResources(locale).getNumberPatterns();
    DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locale);
    int entry = (choice == INTEGERSTYLE) ? NUMBERSTYLE : choice;
    DecimalFormat format = new DecimalFormat(numberPatterns[entry], symbols);

    if (choice == INTEGERSTYLE) {
        format.setMaximumFractionDigits(0);
        format.setDecimalSeparatorAlwaysShown(false);
        format.setParseIntegerOnly(true);
    } else if (choice == CURRENCYSTYLE) {
        adjustForCurrencyDefaultFractionDigits(format, symbols);
    }

    return format;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:23,代码来源:NumberFormatProviderImpl.java

示例2: initializeTextFields

import java.text.DecimalFormatSymbols; //导入依赖的package包/类
private void initializeTextFields() {

		DecimalFormatSymbols symbols = new DecimalFormatSymbols();
		symbols.setDecimalSeparator('.');

		NumberFormat format = new DecimalFormat("0.00", symbols);
		format.setMaximumFractionDigits(2);

		NumberFormatter formatter = new NumberFormatter(format);
		formatter.setMinimum(0.0);
		formatter.setMaximum(10000000.0);
		formatter.setAllowsInvalid(false);

		this.txtPeso = new JFormattedTextField(formatter);
		this.txtPeso.setValue(0.0);

		GridBagConstraints gbc_textField = new GridBagConstraints();
		gbc_textField.gridwidth = 10;
		gbc_textField.insets = new Insets(0, 0, 5, 0);
		gbc_textField.fill = GridBagConstraints.BOTH;
		gbc_textField.gridx = 2;
		gbc_textField.gridy = 10;
		this.panelSecond.add(this.txtPeso, gbc_textField);
		this.txtPeso.setColumns(10);

	}
 
开发者ID:cjlcarvalho,项目名称:LogisticApp,代码行数:27,代码来源:MenuContratacaoTransporteFrame.java

示例3: readTestObject

import java.text.DecimalFormatSymbols; //导入依赖的package包/类
private DecimalFormatSymbols readTestObject(File inputFile){
    try (InputStream istream = inputFile.getName().endsWith(".txt") ?
                                   HexDumpReader.getStreamFromHexDump(inputFile) :
                                   new FileInputStream(inputFile)) {
        ObjectInputStream p = new ObjectInputStream(istream);
        DecimalFormatSymbols dfs = (DecimalFormatSymbols)p.readObject();
        return dfs;
    } catch (Exception e) {
        errln("Test Malfunction in DFSSerialization: Exception while reading the object");
        /*
         * logically should not throw this exception as errln throws exception
         * if not thrown yet - but in case errln got changed
         */
        throw new RuntimeException("Test Malfunction: re-throwing the exception", e);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:DFSSerialization.java

示例4: printTestInfo

import java.text.DecimalFormatSymbols; //导入依赖的package包/类
private void printTestInfo(int maxCacheSize) {

        DecimalFormat grouped = new DecimalFormat("000,000");
        DecimalFormatSymbols formatSymbols = grouped.getDecimalFormatSymbols();
        formatSymbols.setGroupingSeparator(' ');
        grouped.setDecimalFormatSymbols(formatSymbols);

        System.out.format(
                "Test will use %s bytes of memory of %s available%n"
                + "Available memory is %s with %d bytes pointer size - can save %s pointers%n"
                + "Max cache size: 2^%d = %s elements%n",
                grouped.format(ShrinkAuxiliaryDataTest.getMemoryUsedByTest()),
                grouped.format(Runtime.getRuntime().maxMemory()),
                grouped.format(Runtime.getRuntime().maxMemory()
                        - ShrinkAuxiliaryDataTest.getMemoryUsedByTest()),
                Unsafe.ADDRESS_SIZE,
                grouped.format((Runtime.getRuntime().freeMemory()
                        - ShrinkAuxiliaryDataTest.getMemoryUsedByTest())
                        / Unsafe.ADDRESS_SIZE),
                maxCacheSize,
                grouped.format((int) Math.pow(2, maxCacheSize))
        );
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:TestShrinkAuxiliaryData.java

示例5: initialize

import java.text.DecimalFormatSymbols; //导入依赖的package包/类
/**
 * Initializes the panel.
 */
private void initialize() {
	this.setLayout(new GridLayout(0, 1, 10, 10));

	DecimalFormatSymbols symbol = new DecimalFormatSymbols();

	symbol.setDecimalSeparator('.');
	DecimalFormat decimalFormat = new DecimalFormat();
	decimalFormat.setDecimalFormatSymbols(symbol);
	mtFieldFormat = decimalFormat;

	Double expected = firstMoment.evaluate(reliabilityFunction);

	JLabel expectedLabel = new JLabel("Expected Value:");
	JPanel propertiesPanel = createPropertiesPanel(expected, expectedLabel);
	JPanel mttfPanel = createMttfPanel(expected, expectedLabel.getPreferredSize());
	JPanel mtPanel = createMtPanel(expectedLabel.getPreferredSize());

	this.add(propertiesPanel);
	this.add(mttfPanel);
	this.add(mtPanel);

	revalidate();
	repaint();
}
 
开发者ID:felixreimann,项目名称:jreliability,代码行数:28,代码来源:MeasuresPanel.java

示例6: getFormat

import java.text.DecimalFormatSymbols; //导入依赖的package包/类
/**
 * Returns the format used by
 * {@link #convertToPresentation(Object, ValueContext)} and
 * {@link #convertToModel(Object, ValueContext)}.
 *
 * @param context
 *            value context to use
 * @return A NumberFormat instance
 */
protected NumberFormat getFormat(ValueContext context) {
	String pattern = null;

	Object data = context.getComponent().map(AbstractComponent.class::cast).map(component -> component.getData())
			.orElse(null);
	if (data instanceof ColumnDefinition) {
		pattern = ((ColumnDefinition) data).getFormat()
				.orElse(configurationProvider.getNumberFormatPattern().orElse(null));
	}

	Locale locale = context.getLocale().orElse(configurationProvider.getLocale());

	if (pattern == null) {
		return NumberFormat.getNumberInstance(locale);
	}

	return new DecimalFormat(pattern, new DecimalFormatSymbols(locale));
}
 
开发者ID:peterl1084,项目名称:bean-grid,代码行数:28,代码来源:AbstractStringToNumberConverterBean.java

示例7: adjustForCurrencyDefaultFractionDigits

import java.text.DecimalFormatSymbols; //导入依赖的package包/类
/**
 * Adjusts the minimum and maximum fraction digits to values that
 * are reasonable for the currency's default fraction digits.
 */
private static void adjustForCurrencyDefaultFractionDigits(
        DecimalFormat format, DecimalFormatSymbols symbols) {
    Currency currency = symbols.getCurrency();
    if (currency == null) {
        try {
            currency = Currency.getInstance(symbols.getInternationalCurrencySymbol());
        } catch (IllegalArgumentException e) {
        }
    }
    if (currency != null) {
        int digits = currency.getDefaultFractionDigits();
        if (digits != -1) {
            int oldMinDigits = format.getMinimumFractionDigits();
            // Common patterns are "#.##", "#.00", "#".
            // Try to adjust all of them in a reasonable way.
            if (oldMinDigits == format.getMaximumFractionDigits()) {
                format.setMinimumFractionDigits(digits);
                format.setMaximumFractionDigits(digits);
            } else {
                format.setMinimumFractionDigits(Math.min(digits, oldMinDigits));
                format.setMaximumFractionDigits(digits);
            }
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:NumberFormatProviderImpl.java

示例8: toYearMonthString

import java.text.DecimalFormatSymbols; //导入依赖的package包/类
public String toYearMonthString()
{
	StringBuffer s = new StringBuffer();
	if (bNegative)
		s.append("-");
	s.append("P");
	if (year != 0) 
	{
		s.append(new DecimalFormat("0", new DecimalFormatSymbols(java.util.Locale.US)).format( (long) java.lang.Math.abs(year) ) );
		s.append("Y");
	}
	if (month != 0) 
	{
		s.append(new DecimalFormat("0", new DecimalFormatSymbols(java.util.Locale.US)).format( (long) java.lang.Math.abs(month) ) );
		s.append("M");
	}
	if (s.length() == 1)
		s.append("0M");
	return s.toString();
}
 
开发者ID:CenPC434,项目名称:java-tools,代码行数:21,代码来源:Duration.java

示例9: castToString

import java.text.DecimalFormatSymbols; //导入依赖的package包/类
public static String castToString(double d)
{
	double dAbs = Math.abs(d);
	DecimalFormatSymbols decfmtsymb = new DecimalFormatSymbols(java.util.Locale.US);	// US locale represents numbers with a . as comma and without any (ten)thousend separators.
	decfmtsymb.setInfinity("INF");
	decfmtsymb.setNaN("NaN");
	DecimalFormat decfmt = new DecimalFormat((dAbs > 1E7 || dAbs < 1E-3) && dAbs > 0.0 ?
			"0.##############E000" : "0.#############", decfmtsymb);
	
	String s = decfmt.format(d);
	// 1.234E567 => 1.234E+567
	int e = s.indexOf("E");
	if (e > 0 && s.charAt(e+1) != '-' )
	s = s.substring(0, e) + "E+" + s.substring(e+1);
	return s;
}
 
开发者ID:CenPC434,项目名称:java-tools,代码行数:17,代码来源:CoreTypes.java

示例10: initialValue

import java.text.DecimalFormatSymbols; //导入依赖的package包/类
@Override
protected NumberFormat initialValue() {

    // Always create the formatter for the US locale in order to avoid this bug:
    // https://github.com/indeedeng/java-dogstatsd-client/issues/3
    final NumberFormat numberFormatter = NumberFormat.getInstance(Locale.US);
    numberFormatter.setGroupingUsed(false);
    numberFormatter.setMaximumFractionDigits(6);

    // we need to specify a value for Double.NaN that is recognized by dogStatsD
    if (numberFormatter instanceof DecimalFormat) { // better safe than a runtime error
        final DecimalFormat decimalFormat = (DecimalFormat) numberFormatter;
        final DecimalFormatSymbols symbols = decimalFormat.getDecimalFormatSymbols();
        symbols.setNaN("NaN");
        decimalFormat.setDecimalFormatSymbols(symbols);
    }

    return numberFormatter;
}
 
开发者ID:micrometer-metrics,项目名称:micrometer,代码行数:20,代码来源:DoubleFormat.java

示例11: cluster_simplfication

import java.text.DecimalFormatSymbols; //导入依赖的package包/类
public static JSONArray cluster_simplfication(JSONArray coords, double tolerance){
	DecimalFormat df = new DecimalFormat("0.0000");
	DecimalFormatSymbols simbolos = new DecimalFormatSymbols();
	simbolos.setDecimalSeparator('.');
	df.setDecimalFormatSymbols(simbolos);
	double pivotx = coords.getDouble(0);
	double pivoty = coords.getDouble(1);
	JSONArray newcoords = new JSONArray();
	newcoords.put(new Float(df.format(pivotx)));
	newcoords.put(new Float(df.format(pivoty)));
	for(int i=2; i<coords.length(); i++){
		if(Math.sqrt(Math.pow((coords.getDouble(i)-pivotx), 2)+Math.pow((coords.getDouble(i+1)-pivoty), 2)) >= tolerance){
			pivotx = coords.getDouble(i);
			pivoty = coords.getDouble(i+1);
			newcoords.put(new Float(df.format(pivotx)));
			newcoords.put(new Float(df.format(pivoty)));
		}
		i++;
	}
	return newcoords;
}
 
开发者ID:acalvoa,项目名称:EARLGREY,代码行数:22,代码来源:GeoAlgorithm.java

示例12: validateOnlyDigits

import java.text.DecimalFormatSymbols; //导入依赖的package包/类
/**
 * Validates that the given value contains only digits, but not e.g. a
 * character 'd'. Java would interpret the input 3d as double value 3.0.
 * Anyway, this must not succeed.
 * 
 * @param valueToCheck
 *            The value to be checked.
 * @param component
 *            The current component.
 * @return <code>true</code> if the value is valid.
 */
private static boolean validateOnlyDigits(String valueToCheck,
        FacesContext facesContext) {
    Locale locale = LocaleHandler.getLocaleFromString(BaseBean
            .getUserFromSession(facesContext).getLocale());
    DecimalFormatSymbols dfs = new DecimalFormatSymbols(locale);
    boolean decSepFound = false;

    for (char c : valueToCheck.toCharArray()) {
        if (!decSepFound && c == dfs.getDecimalSeparator()) {
            decSepFound = true;
            continue;
        }
        if (c == dfs.getGroupingSeparator()) {
            continue;
        }
        if (!Character.isDigit(c)) {
            return false;
        }
    }

    return true;
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:34,代码来源:DurationValidation.java

示例13: pattern

import java.text.DecimalFormatSymbols; //导入依赖的package包/类
/** Return a representation of the pattern used by this instance for formatting and
 *  parsing.  The format is similar to, but not the same as the format recognized by the
 *  {@link Builder#pattern} and {@link Builder#localizedPattern} methods.  The pattern
 *  returned by this method is localized, any currency signs expressed are literally, and
 *  optional fractional decimal places are shown grouped in parentheses. */
public String pattern() { synchronized(numberFormat) {
    StringBuilder groups = new StringBuilder();
    for (int group : decimalGroups) {
        groups.append("(").append(Strings.repeat("#", group)).append(")");
    }
    DecimalFormatSymbols s = numberFormat.getDecimalFormatSymbols();
    String digit = String.valueOf(s.getDigit());
    String exp = s.getExponentSeparator();
    String groupSep = String.valueOf(s.getGroupingSeparator());
    String moneySep = String.valueOf(s.getMonetaryDecimalSeparator());
    String zero = String.valueOf(s.getZeroDigit());
    String boundary = String.valueOf(s.getPatternSeparator());
    String minus = String.valueOf(s.getMinusSign());
    String decSep = String.valueOf(s.getDecimalSeparator());

    String prefixAndNumber = "(^|" + boundary+ ")" +
        "([^" + Matcher.quoteReplacement(digit + zero + groupSep + decSep + moneySep) + "']*('[^']*')?)*" +
        "[" + Matcher.quoteReplacement(digit + zero + groupSep + decSep + moneySep + exp) + "]+";

    return numberFormat.toLocalizedPattern().
        replaceAll(prefixAndNumber, "$0" + groups.toString()).
           replaceAll("¤¤", Matcher.quoteReplacement(coinCode())).
           replaceAll("¤", Matcher.quoteReplacement(coinSymbol()));
}}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:30,代码来源:BtcFormat.java

示例14: testgetValueToDisplay

import java.text.DecimalFormatSymbols; //导入依赖的package包/类
@Test
public void testgetValueToDisplay() throws Exception {
    final DecimalFormatSymbols dfs = new DecimalFormatSymbols(
            priceConverter.getActiveLocale());
    StringBuffer strMoneyBuffer = new StringBuffer();
    strMoneyBuffer.append("123");
    strMoneyBuffer.append(dfs.getDecimalSeparator());
    strMoneyBuffer.append("45");

    Assert.assertEquals(
            strMoneyBuffer.toString(),
            priceConverter.getValueToDisplay(
                    new BigDecimal(strMoneyBuffer.toString()), true));

    strMoneyBuffer.delete(0, strMoneyBuffer.length());
    strMoneyBuffer.append("123");
    strMoneyBuffer.append(dfs.getDecimalSeparator());
    strMoneyBuffer.append("00");

    Assert.assertEquals(
            "123.00",
            priceConverter.getValueToDisplay(
                    priceConverter.parse(strMoneyBuffer.toString()), true));

}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:26,代码来源:PriceConverterTest.java

示例15: apply

import java.text.DecimalFormatSymbols; //导入依赖的package包/类
@Override
public Object apply(Object input, Map<String, Object> args, PebbleTemplate self, EvaluationContext context, int lineNumber) throws PebbleException{
    if (input == null) {
        return null;
    }
    if (!(input instanceof Number)) {
        throw new PebbleException(null, "The input for the 'NumberFormat' filter has to be a number.", lineNumber, self.getName());
    }

    Number number = (Number) input;

    Locale locale = context.getLocale();

    if (args.get("format") != null) {
        Format format = new DecimalFormat((String) args.get("format"), new DecimalFormatSymbols(locale));
        return format.format(number);
    } else {
        NumberFormat numberFormat = NumberFormat.getInstance(locale);
        return numberFormat.format(number);
    }
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:22,代码来源:NumberFormatFilter.java


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