java.text.DecimalFormat#getDecimalFormatSymbols ( )源码实例Demo

下面列出了java.text.DecimalFormat#getDecimalFormatSymbols ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: TencentKona-8   文件: TestShrinkAuxiliaryData.java
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))
        );
    }
 
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))
        );
    }
 
源代码3 项目: birt   文件: ExcelUtil.java
private static void updateExcelDecimalSeparator( DecimalFormat numberFormat )
{
	DecimalFormatSymbols symbol = numberFormat.getDecimalFormatSymbols( );
	if ( symbol.getDecimalSeparator( ) != EXCEL_DECIMAL_SEPARATOR )
	{
		symbol.setDecimalSeparator( EXCEL_DECIMAL_SEPARATOR );
		numberFormat.setDecimalFormatSymbols( symbol );
	}
}
 
源代码4 项目: j2objc   文件: DecimalFormatTest.java
public void test_exponentSeparator() throws Exception {
    DecimalFormat df = new DecimalFormat("0E0");
    assertEquals("1E4", df.format(12345.));

    DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();
    dfs.setExponentSeparator("-useless-api-");
    df.setDecimalFormatSymbols(dfs);
    assertEquals("1-useless-api-4", df.format(12345.));
}
 
源代码5 项目: GreenBits   文件: BtcFormat.java
/** Set the currency symbol and international code of the underlying {@link
  * java.text.NumberFormat} object to the values of the last two arguments, respectively.
  * This method is invoked in the process of parsing, not formatting.
  *
  * Only invoke this from code synchronized on value of the first argument, and don't
  * forget to put the symbols back otherwise equals(), hashCode() and immutability will
  * break.  */
private static DecimalFormatSymbols setSymbolAndCode(DecimalFormat numberFormat, String symbol, String code) {
    checkState(Thread.holdsLock(numberFormat));
    DecimalFormatSymbols fs = numberFormat.getDecimalFormatSymbols();
    DecimalFormatSymbols ante = (DecimalFormatSymbols)fs.clone();
    fs.setInternationalCurrencySymbol(code);
    fs.setCurrencySymbol(symbol);
    numberFormat.setDecimalFormatSymbols(fs);
    return ante;
}
 
private UserSessionLocale(final String adLanguage)
{
	final Language language = Language.getLanguage(adLanguage);
	if (language == null)
	{
		throw new IllegalArgumentException("No language found for " + adLanguage);
	}
	this.adLanguage = language.getAD_Language();

	final DecimalFormat decimalFormat = DisplayType.getNumberFormat(DisplayType.Amount, language);
	final DecimalFormatSymbols decimalFormatSymbols = decimalFormat.getDecimalFormatSymbols();
	numberDecimalSeparator = decimalFormatSymbols.getDecimalSeparator();
	numberGroupingSeparator = decimalFormatSymbols.getGroupingSeparator();
}
 
源代码7 项目: PyramidShader   文件: CatmullRomSpline.java
@Override
public String toString() {
    DecimalFormat formatter = new DecimalFormat("##0.####");
    DecimalFormatSymbols dfs = formatter.getDecimalFormatSymbols();
    dfs.setDecimalSeparator('.');
    formatter.setDecimalFormatSymbols(dfs);
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < this.x.length; i++) {
        sb.append(formatter.format(x[i]));
        sb.append(" ");
        sb.append(formatter.format(y[i]));
        sb.append(" ");
    }
    return sb.toString();
}
 
源代码8 项目: openjdk-jdk9   文件: TestgetPatternSeparator_ja.java
public static void main(String[] argv) throws Exception {
    DecimalFormat df = (DecimalFormat)NumberFormat.getInstance(Locale.JAPAN);
    DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();
    if (dfs.getPatternSeparator() != ';') {
        throw new Exception("DecimalFormatSymbols.getPatternSeparator doesn't return ';' in ja locale");
    }
}
 
public static void main(String[] argv) throws Exception {
    DecimalFormat df = (DecimalFormat)NumberFormat.getInstance(Locale.JAPAN);
    DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();
    if (dfs.getPatternSeparator() != ';') {
        throw new Exception("DecimalFormatSymbols.getPatternSeparator doesn't return ';' in ja locale");
    }
}
 
源代码10 项目: openjdk-jdk9   文件: Helpers.java
/**
 * @return a number formatter instance which prints numbers in a human
 * readable form, like 9_223_372_036_854_775_807.
 */
public static NumberFormat numberFormatter() {
    DecimalFormat df = new DecimalFormat();
    DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();
    dfs.setGroupingSeparator('_');
    dfs.setDecimalSeparator('.');
    df.setDecimalFormatSymbols(dfs);
    return df;
}
 
源代码11 项目: Knowage-Server   文件: GeneralUtilities.java
public static char getGroupingSeparator(Locale locale) {
	DecimalFormat df = (DecimalFormat) DecimalFormat.getInstance(locale);
	DecimalFormatSymbols decimalFormatSymbols = df.getDecimalFormatSymbols();
	logger.debug("IN");
	char thousands = decimalFormatSymbols.getGroupingSeparator();

	logger.debug("OUT");
	return thousands;
}
 
源代码12 项目: marvinproject   文件: MarvinMatrixPanel.java
public MarvinMatrixPanel(int rows, int columns){
	this.rows = rows;
	this.columns = columns;
	
	JPanel panelTextFields = new JPanel();
	GridLayout layout = new GridLayout(rows, columns);
	
	panelTextFields.setLayout(layout);
	
	//Format
	DecimalFormat decimalFormat = new DecimalFormat();
	DecimalFormatSymbols dfs = decimalFormat.getDecimalFormatSymbols();
	dfs.setDecimalSeparator('.');
	decimalFormat.setDecimalFormatSymbols(dfs);
	
	textFields = new JFormattedTextField[rows][columns];
	for(int r=0; r<rows; r++){
		for(int c=0; c<columns; c++){
			
			textFields[r][c] = new JFormattedTextField(decimalFormat);
			textFields[r][c].setValue(0.0);
			textFields[r][c].setColumns(4);
			panelTextFields.add(textFields[r][c]);
			
		}
	}
	
	setLayout(new FlowLayout(FlowLayout.CENTER));
	add(panelTextFields);
}
 
源代码13 项目: RxAndroidBootstrap   文件: DecimalFormatUtil.java
/**
 * Returns a thousans separated decimar formatter.
 *
 * @return
 */
public static DecimalFormat getThousandSeperatedDecimalFormat() {
    DecimalFormat df = (DecimalFormat) NumberFormat.getInstance(Locale.US);
    DecimalFormatSymbols symbols = df.getDecimalFormatSymbols();
    symbols.setGroupingSeparator(' ');
    df.setDecimalFormatSymbols(symbols);
    return df;
}
 
源代码14 项目: green_android   文件: UI.java
public static void localeDecimalInput(final EditText editText) {
    final DecimalFormat decFormat = (DecimalFormat) DecimalFormat.getInstance(Locale.getDefault());
    final DecimalFormatSymbols symbols=decFormat.getDecimalFormatSymbols();
    final String defaultSeparator = Character.toString(symbols.getDecimalSeparator());
    final String otherSeparator = ".".equals(defaultSeparator) ? "," : ".";

    editText.setHint(String.format("0%s00",defaultSeparator));

    editText.addTextChangedListener(new TextWatcher() {
        private boolean isEditing =false;
        @Override
        public void onTextChanged(final CharSequence s, final int start, final int before, final int count) {
            Log.d(TAG,s + " " + start + " " + before + " " + count);
        }


        @Override
        public void afterTextChanged(Editable editable) {
            if (isEditing)
                return;
            isEditing = true;
            final int index = editable.toString().indexOf(otherSeparator);
            if (index > 0)
                editable.replace(index,index+1, defaultSeparator);

            if (editable.toString().contains(".") || editable.toString().contains(","))
                editText.setKeyListener(DigitsKeyListener.getInstance("0123456789"));
            else
                editText.setKeyListener(DigitsKeyListener.getInstance("0123456789.,"));

            isEditing =false;
        }
    });
}
 
源代码15 项目: green_android   文件: BtcFormat.java
/** Set the currency symbol and international code of the underlying {@link
  * java.text.NumberFormat} object to the values of the last two arguments, respectively.
  * This method is invoked in the process of parsing, not formatting.
  *
  * Only invoke this from code synchronized on value of the first argument, and don't
  * forget to put the symbols back otherwise equals(), hashCode() and immutability will
  * break.  */
private static DecimalFormatSymbols setSymbolAndCode(DecimalFormat numberFormat, String symbol, String code) {
    checkState(Thread.holdsLock(numberFormat));
    DecimalFormatSymbols fs = numberFormat.getDecimalFormatSymbols();
    DecimalFormatSymbols ante = (DecimalFormatSymbols)fs.clone();
    fs.setInternationalCurrencySymbol(code);
    fs.setCurrencySymbol(symbol);
    numberFormat.setDecimalFormatSymbols(fs);
    return ante;
}
 
源代码16 项目: SaneEconomy   文件: Currency.java
public static Currency fromConfig(ConfigurationSection config) {
    DecimalFormat format = new DecimalFormat(config.getString("format", "0.00"));

    if (config.getInt("grouping", 0) > 0) {
        DecimalFormatSymbols symbols = format.getDecimalFormatSymbols();
        if (symbols.getDecimalSeparator() == ',') { // French
            symbols.setGroupingSeparator(' ');
        } else {
            symbols.setGroupingSeparator(',');
        }

        String groupingSeparator = config.getString("grouping-separator", null);

        if (!Strings.isNullOrEmpty(groupingSeparator)) {
            symbols.setGroupingSeparator(groupingSeparator.charAt(0));
        }

        String decimalSeparator = config.getString("decimal-separator", ".");

        if (!Strings.isNullOrEmpty(decimalSeparator)) {
            symbols.setDecimalSeparator(decimalSeparator.charAt(0));
        }

        format.setDecimalFormatSymbols(symbols);
        format.setGroupingUsed(true);
        format.setGroupingSize(3);
    }

    return new Currency(
               config.getString("name.singular", "dollar"),
               config.getString("name.plural", "dollars"),
               format,
               config.getString("balance-format", "{1} {2}")
           );
}
 
源代码17 项目: mjprof   文件: StackTreeTest.java
private static char getSeparator() {
           DecimalFormat format= (DecimalFormat) DecimalFormat.getInstance();
            DecimalFormatSymbols symbols=format.getDecimalFormatSymbols();
            char sep=symbols.getDecimalSeparator();
            return sep;
}
 
源代码18 项目: mycore   文件: MCRDecimalConverter.java
private boolean hasMultipleDecimalSeparators(String string, DecimalFormat df) {
    DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();
    String patternNonDecimalSeparators = "[^" + dfs.getDecimalSeparator() + "]";
    String decimalSeparatorsLeftOver = string.replaceAll(patternNonDecimalSeparators, "");
    return (decimalSeparatorsLeftOver.length() > 1);
}
 
源代码19 项目: bcm-android   文件: BtcFormat.java
/**
 * Set both the currency symbol and code of the underlying, mutable NumberFormat object
 * according to the given denominational units scale factor.  This is for formatting, not parsing.
 * <p>
 * <p>Set back to zero when you're done formatting otherwise immutability, equals() and
 * hashCode() will break!
 *
 * @param scale Number of places the decimal point will be shifted when formatting
 *              a quantity of satoshis.
 */
protected static void prefixUnitsIndicator(DecimalFormat numberFormat, int scale) {
    checkState(Thread.holdsLock(numberFormat)); // make sure caller intends to reset before changing
    DecimalFormatSymbols fs = numberFormat.getDecimalFormatSymbols();
    setSymbolAndCode(numberFormat,
            prefixSymbol(fs.getCurrencySymbol(), scale), prefixCode(fs.getInternationalCurrencySymbol(), scale)
    );
}
 
源代码20 项目: MeteoInfo   文件: NumberExpression.java
/**
 * Determines whether the specified char is a number
 *
 * @param c The char
 * @return If the char is a digit or a decimal separator
 */
public static boolean isNumber(char c) {
    DecimalFormat format = (DecimalFormat) DecimalFormat.getInstance();
    DecimalFormatSymbols symbols = format.getDecimalFormatSymbols();
    return Character.isDigit(c) || symbols.getDecimalSeparator() == c;
}