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

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

源代码1 项目: JavaMainRepo   文件: Polynomial.java
public String toString() {
	DecimalFormat format = new DecimalFormat();
	format.setDecimalSeparatorAlwaysShown(false);
	String pol = "";
	int d = getDegree();
	for (int i = d; i >= 0; i--) {
		if (i == 1) {
			if (coeffs[0] >= 0) {
				pol += format.format(coeffs[i]) + "X+";
			} else {
				pol += format.format(coeffs[i]) + "X";
			}
		} else if (i == 0) {
			pol += format.format(coeffs[i]);
		} else {
			if (coeffs[i - 1] >= 0) {
				pol += format.format(coeffs[i]) + "X^" + i + "+";
			} else {
				pol += format.format(coeffs[i]) + "X^" + i;
			}
		}
	}
	return pol;
}
 
源代码2 项目: jdk8u60   文件: NumberFormatProviderImpl.java
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;
}
 
源代码3 项目: jdk8u-dev-jdk   文件: NumberFormatProviderImpl.java
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;
}
 
源代码4 项目: openjdk-jdk8u   文件: NumberFormatProviderImpl.java
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;
}
 
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;
}
 
源代码6 项目: openjdk-jdk9   文件: NumberFormatProviderImpl.java
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;
}
 
源代码7 项目: jdk8u-jdk   文件: NumberFormatProviderImpl.java
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;
}
 
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;
}
 
源代码9 项目: openjdk-8   文件: NumberFormatProviderImpl.java
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;
}
 
/**
 * Initialise the abstract graphics document, specifically meant to set the formatter.
 *
 * @param defaultMaxDigits default max digits
 */
public AbstractGraphicsDocument(int defaultMaxDigits) {
	Locale locale = new Locale("en", "US");
	DecimalFormatSymbols decimalSymbols = new DecimalFormatSymbols(locale);
	decimalSymbols.setDecimalSeparator('.');
	formatter = new DecimalFormat();
	formatter.setDecimalFormatSymbols(decimalSymbols);

	// do not group
	formatter.setGroupingSize(0);

	// do not show decimal SEPARATOR if it is not needed
	formatter.setDecimalSeparatorAlwaysShown(false);
	formatter.setGroupingUsed(false);

	// set default number of fraction digits
	formatter.setMaximumFractionDigits(defaultMaxDigits);

	// minimum fraction digits to 0 so they get not rendered if not needed
	formatter.setMinimumFractionDigits(0);
}
 
源代码11 项目: JANNLab   文件: DoubleTools.java
public static String asString(final double value, final int decimals) {
    //
    DecimalFormat f = new DecimalFormat();
    f.setDecimalSeparatorAlwaysShown(true);
    f.setMaximumFractionDigits(decimals);
    f.setMinimumFractionDigits(decimals);
    f.setGroupingUsed(false);
    //
    f.setDecimalFormatSymbols(new DecimalFormatSymbols() {
        private static final long serialVersionUID = -2464236658633690492L;
        public char getGroupingSeparator() { return ' '; }
        public char getDecimalSeparator() { return '.'; }
    });
    return f.format(value);    
}
 
源代码12 项目: FancyBing   文件: Komi.java
public String toString()
{
    DecimalFormat format =
        (DecimalFormat)(NumberFormat.getInstance(Locale.ENGLISH));
    format.setGroupingUsed(false);
    format.setDecimalSeparatorAlwaysShown(false);
    return format.format(m_value);
}
 
源代码13 项目: fingen   文件: NumberTextWatcher.java
public NumberTextWatcher(EditText et, TextWatcher textWatcher) {
    mTextWatcher = textWatcher;
    DecimalFormatSymbols symbols = new DecimalFormatSymbols();
    symbols.setDecimalSeparator('.');
    symbols.setGroupingSeparator(' ');
    df = new DecimalFormat("#,###.##");
    df.setDecimalSeparatorAlwaysShown(true);
    df.setDecimalFormatSymbols(symbols);
    dfnd = new DecimalFormat("#,###");
    dfnd.setDecimalFormatSymbols(symbols);
    this.et = et;
    hasFractionalPart = false;
}
 
源代码14 项目: financisto   文件: CurrencyCache.java
public static DecimalFormat createCurrencyFormat(Currency c) {
	DecimalFormatSymbols dfs = new DecimalFormatSymbols();
	dfs.setDecimalSeparator(charOrEmpty(c.decimalSeparator, dfs.getDecimalSeparator()));
	dfs.setGroupingSeparator(charOrEmpty(c.groupSeparator, dfs.getGroupingSeparator()));
	dfs.setMonetaryDecimalSeparator(dfs.getDecimalSeparator());
	dfs.setCurrencySymbol(c.symbol);

	DecimalFormat df = new DecimalFormat("#,##0.00", dfs);
	df.setGroupingUsed(dfs.getGroupingSeparator() > 0);
	df.setMinimumFractionDigits(c.decimals);
	df.setMaximumFractionDigits(c.decimals);
	df.setDecimalSeparatorAlwaysShown(false);
	return df;
}
 
源代码15 项目: Canova   文件: StringUtils.java
/**
 * Format a percentage for presentation to the user.
 * @param done the percentage to format (0.0 to 1.0)
 * @param digits the number of digits past the decimal point
 * @return a string representation of the percentage
 */
public static String formatPercent(double done, int digits) {
    DecimalFormat percentFormat = new DecimalFormat("0.00%");
    double scale = Math.pow(10.0, digits+2);
    double rounded = Math.floor(done * scale);
    percentFormat.setDecimalSeparatorAlwaysShown(false);
    percentFormat.setMinimumFractionDigits(digits);
    percentFormat.setMaximumFractionDigits(digits);
    return percentFormat.format(rounded / scale);
}
 
源代码16 项目: snap-desktop   文件: RangeEditorDialog.java
DoubleFormatter(String pattern) {
    final DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(Locale.ENGLISH);
    format = new DecimalFormat(pattern, decimalFormatSymbols);

    format.setParseIntegerOnly(false);
    format.setParseBigDecimal(false);
    format.setDecimalSeparatorAlwaysShown(true);
}
 
源代码17 项目: scava   文件: Utils.java
public static String formatPercent(double done, int digits) {
	DecimalFormat percentFormat = new DecimalFormat("0.0%");
	percentFormat.setDecimalSeparatorAlwaysShown(false);
	percentFormat.setMinimumFractionDigits(digits);
	percentFormat.setMaximumFractionDigits(digits);
	return percentFormat.format(done);

}
 
源代码18 项目: aes-rsa-java   文件: ConvertUtils.java
public static final String objectToString(Object obj, DecimalFormat fmt)
{
    fmt.setDecimalSeparatorAlwaysShown(false);
    if(obj instanceof Double)
        return fmt.format(((Double)obj).doubleValue());
    if(obj instanceof Long)
        return fmt.format(((Long)obj).longValue());
    else
        return obj.toString();
}
 
源代码19 项目: snap-desktop   文件: DecimalFormatter.java
public DecimalFormatter(String pattern) {
    final DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(Locale.ENGLISH);
    format = new DecimalFormat(pattern, decimalFormatSymbols);
    format.setParseIntegerOnly(false);
    format.setParseBigDecimal(false);
    format.setDecimalSeparatorAlwaysShown(true);
}
 
源代码20 项目: incubator-hivemall   文件: DateTimeFormatter.java
private static String formatNumber(final double number, boolean commaSep) {
    DecimalFormat f = new DecimalFormat(commaSep ? "#,###.###" : "###.###");
    f.setDecimalSeparatorAlwaysShown(false);
    return f.format(number);
}