本文整理匯總了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;
}
示例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);
}
示例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);
}
}
示例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))
);
}
示例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();
}
示例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));
}
示例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);
}
}
}
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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()));
}}
示例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));
}
示例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);
}
}