java.text.DecimalFormatSymbols#getInstance ( )源码实例Demo

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

源代码1 项目: nordpos   文件: JRViewer.java
/**
 *
 */
protected void initResources(Locale locale, ResourceBundle resBundle)
{
	//FIXME in theory, the setLocale method could be called after current Component was created, in which case all below should be reloaded
	if (locale != null)
	{
		setLocale(locale);
	}
	else
	{
		setLocale(Locale.getDefault());
	}
	if (resBundle == null)
	{
		this.resourceBundle = ResourceBundle.getBundle("net/sf/jasperreports/view/viewer", getLocale());
	}
	else
	{
		this.resourceBundle = resBundle;
	}

	zoomDecimalFormat = new DecimalFormat("#.##", DecimalFormatSymbols.getInstance(getLocale()));
}
 
public void testParseFloatNonRootLocale() throws Exception {
  final DecimalFormatSymbols fr_FR = DecimalFormatSymbols.getInstance(new Locale("fr","FR"));
  final char groupChar = fr_FR.getGroupingSeparator();
  final char decimalChar = fr_FR.getDecimalSeparator();

  float value = 10898.83491F;
  String floatString1 = "10898"+decimalChar+"83491";
  String floatString2 = "10"+groupChar+"898"+decimalChar+"83491";
  
  IndexSchema schema = h.getCore().getLatestSchema();
  assertNotNull(schema.getFieldOrNull("float_f")); // should match dynamic field "*_f"
  assertNull(schema.getFieldOrNull("not_in_schema"));
  SolrInputDocument d = processAdd("parse-float-french-no-run-processor",
      doc(f("id", "140"), f("float_f", floatString1),
          f("not_in_schema", floatString2)));
  assertNotNull(d);
  assertThat(d.getFieldValue("float_f"), IS_FLOAT);
  assertEquals(value, (Float)d.getFieldValue("float_f"), EPSILON);
  assertThat(d.getFieldValue("not_in_schema"), IS_FLOAT);
  assertEquals(value, (Float)d.getFieldValue("not_in_schema"), EPSILON);
}
 
源代码3 项目: Bytecoder   文件: DecimalFormatSymbolsTest.java
@Test
public void testLocaleen_US() {
    final DecimalFormatSymbols theSymbols = DecimalFormatSymbols.getInstance(new Locale("en","US"));
    Assert.assertEquals("0", toString(theSymbols.getZeroDigit()));
    Assert.assertEquals(",", toString(theSymbols.getGroupingSeparator()));
    Assert.assertEquals(".", toString(theSymbols.getDecimalSeparator()));
    //Assert.assertEquals("‰", toString(theSymbols.getPerMill()));
    Assert.assertEquals("%", toString(theSymbols.getPercent()));
    Assert.assertEquals("#", toString(theSymbols.getDigit()));
    Assert.assertEquals(";", toString(theSymbols.getPatternSeparator()));
    //Assert.assertEquals("∞", theSymbols.getInfinity());
    //Assert.assertEquals("NaN", theSymbols.getNaN());
    Assert.assertEquals("-", toString(theSymbols.getMinusSign()));
    Assert.assertEquals("$", theSymbols.getCurrencySymbol());
    Assert.assertEquals("USD", theSymbols.getInternationalCurrencySymbol());
    Assert.assertEquals(".", toString(theSymbols.getMonetaryDecimalSeparator()));
    Assert.assertEquals("E", theSymbols.getExponentSeparator());
}
 
源代码4 项目: sax-vsm_classic   文件: Cluster.java
/**
 * Formats the double flow-point number.
 * 
 * @param number The number to format.
 * @return formatted flow-point.
 */
private String formatNumber(double number) {
  DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance();
  symbols.setDecimalSeparator('.');
  DecimalFormat format = new DecimalFormat("#.##########", symbols);
  return format.format(number);
}
 
源代码5 项目: nifi   文件: ConvertExcelToCSVProcessorTest.java
@Test
public void testCustomValueSeparatorWithEL() throws Exception {
    Map<String, String> attributes = new HashMap<String, String>();
    attributes.put("csv.delimiter", "|");
    testRunner.enqueue(new File("src/test/resources/dataformatting.xlsx").toPath(), attributes);

    testRunner.setProperty(CSVUtils.VALUE_SEPARATOR, "${csv.delimiter}");
    testRunner.setProperty(ConvertExcelToCSVProcessor.FORMAT_VALUES, "true");

    testRunner.run();

    testRunner.assertTransferCount(ConvertExcelToCSVProcessor.SUCCESS, 1);
    testRunner.assertTransferCount(ConvertExcelToCSVProcessor.ORIGINAL, 1);
    testRunner.assertTransferCount(ConvertExcelToCSVProcessor.FAILURE, 0);

    MockFlowFile ff = testRunner.getFlowFilesForRelationship(ConvertExcelToCSVProcessor.SUCCESS).get(0);
    Long rowsSheet = new Long(ff.getAttribute(ConvertExcelToCSVProcessor.ROW_NUM));
    assertTrue(rowsSheet == 9);

    LocalDateTime localDt = LocalDateTime.of(2017, 1, 1, 12, 0, 0);
    DecimalFormatSymbols decimalFormatSymbols = DecimalFormatSymbols.getInstance();
    String valueSeparator = testRunner.getProcessContext().getProperty(CSVUtils.VALUE_SEPARATOR).evaluateAttributeExpressions(ff).getValue();
    String decimalSeparator = (String.valueOf(decimalFormatSymbols.getDecimalSeparator()).equals(valueSeparator))
            ? ("\\" + decimalFormatSymbols.getDecimalSeparator()) : String.valueOf(decimalFormatSymbols.getDecimalSeparator());
    String groupingSeparator = String.valueOf(decimalFormatSymbols.getGroupingSeparator()).equals(valueSeparator)
            ? "\\" + decimalFormatSymbols.getGroupingSeparator() : String.valueOf(decimalFormatSymbols.getGroupingSeparator());
    ff.assertContentEquals(String.format("Numbers|Timestamps|Money\n" +
            "1234%1$s456|" + DateTimeFormatter.ofPattern("d/M/yy").format(localDt) + "|$   123%1$s45\n" +
            "1234%1$s46|" + DateTimeFormatter.ofPattern("hh:mm:ss a").format(localDt) + "|£   123%1$s45\n" +
            "1234%1$s5|" + DateTimeFormatter.ofPattern("EEEE, MMMM dd, yyyy").format(localDt) + "|¥   123%1$s45\n" +
            "1%2$s234%1$s46|" + DateTimeFormatter.ofPattern("d/M/yy HH:mm").format(localDt) + "|$   1%2$s023%1$s45\n" +
            "1%2$s234%1$s4560|" + DateTimeFormatter.ofPattern("hh:mm a").format(localDt) + "|£   1%2$s023%1$s45\n" +
            "9%1$s88E+08|" + DateTimeFormatter.ofPattern("yyyy/MM/dd/ HH:mm").format(localDt) + "|¥   1%2$s023%1$s45\n" +
            "9%1$s877E+08||\n" +
            "9%1$s8765E+08||\n", decimalSeparator, groupingSeparator));
}
 
源代码6 项目: Bytecoder   文件: Formatter.java
private static char getZero(Locale l) {
    if ((l != null) && !l.equals(Locale.US)) {
        DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(l);
        return dfs.getZeroDigit();
    } else {
        return '0';
    }
}
 
源代码7 项目: JDKSourceCode1.8   文件: DecimalStyle.java
private static DecimalStyle create(Locale locale) {
    DecimalFormatSymbols oldSymbols = DecimalFormatSymbols.getInstance(locale);
    char zeroDigit = oldSymbols.getZeroDigit();
    char positiveSign = '+';
    char negativeSign = oldSymbols.getMinusSign();
    char decimalSeparator = oldSymbols.getDecimalSeparator();
    if (zeroDigit == '0' && negativeSign == '-' && decimalSeparator == '.') {
        return STANDARD;
    }
    return new DecimalStyle(zeroDigit, positiveSign, negativeSign, decimalSeparator);
}
 
源代码8 项目: ShoppingList   文件: CustomEditTextWatcher.java
private int countDecimalSeparator(CharSequence strValue) {
	DecimalFormatSymbols d = DecimalFormatSymbols.getInstance(Locale.getDefault());
	int posStart = String.valueOf(strValue).indexOf(d.getDecimalSeparator());

	if (posStart > -1) {
		int posEnd = String.valueOf(strValue).lastIndexOf(d.getDecimalSeparator());

		return posStart == posEnd ? 1 : 2;
	}
	return 0;
}
 
源代码9 项目: jdk8u-jdk   文件: Formatter.java
private static char getZero(Locale l) {
    if ((l != null) && !l.equals(Locale.US)) {
        DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(l);
        return dfs.getZeroDigit();
    } else {
        return '0';
    }
}
 
/**
 * 数値のフォーマッタを作成する。
 * <p>アノテーション{@link CsvNumberFormat}の値を元に作成します。</p>
 * @param field フィールド情報
 * @param config システム設定
 * @return アノテーション{@link CsvNumberFormat}が付与されていない場合は、空を返す。
 */
@SuppressWarnings("unchecked")
protected Optional<NumberFormatWrapper<N>> createFormatter(final FieldAccessor field, final Configuration config) {
    
    final Optional<CsvNumberFormat> formatAnno = field.getAnnotation(CsvNumberFormat.class);
    
    if(!formatAnno.isPresent()) {
        return Optional.empty();
    }
    
    final String pattern = formatAnno.get().pattern();
    if(pattern.isEmpty()) {
        return Optional.empty();
    }
    
    final boolean lenient = formatAnno.get().lenient();
    final Locale locale = Utils.getLocale(formatAnno.get().locale());
    final Optional<Currency> currency = formatAnno.get().currency().isEmpty() ? Optional.empty()
            : Optional.of(Currency.getInstance(formatAnno.get().currency()));
    final RoundingMode roundingMode = formatAnno.get().rounding();
    final DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locale);
    
    final DecimalFormat formatter = new DecimalFormat(pattern, symbols);
    formatter.setParseBigDecimal(true);
    formatter.setRoundingMode(roundingMode);
    currency.ifPresent(c -> formatter.setCurrency(c));
    
    final NumberFormatWrapper<N> wrapper = new NumberFormatWrapper<>(formatter, (Class<N>)field.getType(), lenient);
    wrapper.setValidationMessage(formatAnno.get().message());
    
    return Optional.of(wrapper);
    
}
 
源代码11 项目: openjdk-jdk9   文件: Formatter.java
private char getZero(Locale l) {
    if ((l != null) &&  !l.equals(locale())) {
        DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(l);
        return dfs.getZeroDigit();
    }
    return zero;
}
 
源代码12 项目: jpx   文件: LocationFormatterTest.java
@Test
public void testParsePattern() {
	Locale.setDefault(Locale.GERMANY);
	DecimalFormatSymbols instance = DecimalFormatSymbols.getInstance();
	Location location = Location.of(Latitude.ofDegrees(23.987635));
	LocationFormatter locationFormatter = LocationFormatter.builder()
		.appendPattern("DD.DD")
		.build();
	Assert.assertEquals(instance.getDecimalSeparator(), ',');
	Assert.assertEquals(locationFormatter.toPattern(), "DD.DD");
	Assert.assertEquals(locationFormatter.format(location), "23.99");
}
 
private void updateFee() {

        BigInteger defaultGasLimit = BigInteger.valueOf(DEFAULT_GAS_LIMIT);
        BigInteger fee = BigInteger.ZERO;
        if (gasPrice != null) {
            fee = gasPrice.multiply(defaultGasLimit);
        }
        currentFeeEth = Convert.fromWei(new BigDecimal(fee), Convert.Unit.ETHER);
        DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance();
        symbols.setDecimalSeparator('.');
        DecimalFormat decimalFormat = new DecimalFormat(ETH_SHOW_PATTERN, symbols);
        String feeStr = decimalFormat.format(currentFeeEth);
        etFeeAmount.setText(feeStr);
        updateArrivalField();
    }
 
源代码14 项目: j2objc   文件: DecimalStyle.java
private static DecimalStyle create(Locale locale) {
    DecimalFormatSymbols oldSymbols = DecimalFormatSymbols.getInstance(locale);
    char zeroDigit = oldSymbols.getZeroDigit();
    char positiveSign = '+';
    char negativeSign = oldSymbols.getMinusSign();
    char decimalSeparator = oldSymbols.getDecimalSeparator();
    if (zeroDigit == '0' && negativeSign == '-' && decimalSeparator == '.') {
        return STANDARD;
    }
    return new DecimalStyle(zeroDigit, positiveSign, negativeSign, decimalSeparator);
}
 
源代码15 项目: jasperreports   文件: ChartUtil.java
public TickUnitSource createIntegerTickUnits(Locale locale)
{
       DecimalFormatSymbols formatSymbols = DecimalFormatSymbols.getInstance(locale);
       
	// copied from NumberAxis.createIntegerTickUnits() to preserve backward behaviour
       TickUnits units = new TickUnits();
	DecimalFormat df0 = new DecimalFormat("0", formatSymbols);
       DecimalFormat df1 = new DecimalFormat("#,##0", formatSymbols);
       units.add(new NumberTickUnit(1, df0));
       units.add(new NumberTickUnit(2, df0));
       units.add(new NumberTickUnit(5, df0));
       units.add(new NumberTickUnit(10, df0));
       units.add(new NumberTickUnit(20, df0));
       units.add(new NumberTickUnit(50, df0));
       units.add(new NumberTickUnit(100, df0));
       units.add(new NumberTickUnit(200, df0));
       units.add(new NumberTickUnit(500, df0));
       units.add(new NumberTickUnit(1000, df1));
       units.add(new NumberTickUnit(2000, df1));
       units.add(new NumberTickUnit(5000, df1));
       units.add(new NumberTickUnit(10000, df1));
       units.add(new NumberTickUnit(20000, df1));
       units.add(new NumberTickUnit(50000, df1));
       units.add(new NumberTickUnit(100000, df1));
       units.add(new NumberTickUnit(200000, df1));
       units.add(new NumberTickUnit(500000, df1));
       units.add(new NumberTickUnit(1000000, df1));
       units.add(new NumberTickUnit(2000000, df1));
       units.add(new NumberTickUnit(5000000, df1));
       units.add(new NumberTickUnit(10000000, df1));
       units.add(new NumberTickUnit(20000000, df1));
       units.add(new NumberTickUnit(50000000, df1));
       units.add(new NumberTickUnit(100000000, df1));
       units.add(new NumberTickUnit(200000000, df1));
       units.add(new NumberTickUnit(500000000, df1));
       units.add(new NumberTickUnit(1000000000, df1));
       units.add(new NumberTickUnit(2000000000, df1));
       units.add(new NumberTickUnit(5000000000.0, df1));
       units.add(new NumberTickUnit(10000000000.0, df1));
	
	// adding further values by default because 1E10 is not enough for some people
	// using getNumberInstance because that's what NumberAxis.createIntegerTickUnits does
	units.add(new NumberTickUnit(20000000000L, df1));
	units.add(new NumberTickUnit(50000000000L, df1));
	units.add(new NumberTickUnit(100000000000L, df1));
	units.add(new NumberTickUnit(200000000000L, df1));
	units.add(new NumberTickUnit(500000000000L, df1));
	units.add(new NumberTickUnit(1000000000000L, df1));
	units.add(new NumberTickUnit(2000000000000L, df1));
	units.add(new NumberTickUnit(5000000000000L, df1));
	units.add(new NumberTickUnit(10000000000000L, df1));
	units.add(new NumberTickUnit(20000000000000L, df1));
	units.add(new NumberTickUnit(50000000000000L, df1));
	units.add(new NumberTickUnit(100000000000000L, df1));
	units.add(new NumberTickUnit(200000000000000L, df1));
	units.add(new NumberTickUnit(500000000000000L, df1));
	units.add(new NumberTickUnit(1000000000000000L, df1));
	units.add(new NumberTickUnit(2000000000000000L, df1));
	units.add(new NumberTickUnit(5000000000000000L, df1));
	units.add(new NumberTickUnit(10000000000000000L, df1));
	units.add(new NumberTickUnit(20000000000000000L, df1));
	units.add(new NumberTickUnit(50000000000000000L, df1));
	units.add(new NumberTickUnit(100000000000000000L, df1));
	units.add(new NumberTickUnit(200000000000000000L, df1));
	units.add(new NumberTickUnit(500000000000000000L, df1));
	units.add(new NumberTickUnit(1000000000000000000L, df1));
	units.add(new NumberTickUnit(2000000000000000000L, df1));
	units.add(new NumberTickUnit(5000000000000000000L, df1));
	
	return units;
}
 
源代码16 项目: openjdk-jdk8u   文件: LocaleEnhanceTest.java
private void checkDigit(Locale loc, Character expected) {
    DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(loc);
    Character zero = dfs.getZeroDigit();
    assertEquals("Wrong digit zero char", expected, zero);
}
 
源代码17 项目: jdk8u-jdk   文件: LocaleEnhanceTest.java
private void checkDigit(Locale loc, Character expected) {
    DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(loc);
    Character zero = dfs.getZeroDigit();
    assertEquals("Wrong digit zero char", expected, zero);
}
 
源代码18 项目: 600SeriesAndroidUploader   文件: FormatKit.java
public String formatAsHoursMinutes(int hours, int minutes) {
    DecimalFormat df = new DecimalFormat("00", DecimalFormatSymbols.getInstance(Locale.getDefault()));
    return hours + ":" + df.format(minutes);
}
 
源代码19 项目: 600SeriesAndroidUploader   文件: PumpHistoryMisc.java
private String formatCalibrations() {

        // MongoDB Index Key Limit
        // The total size of an index entry, which can include structural overhead depending on the BSON type,
        // must be less than 1024 bytes.

        // This is enough space for around 17 formatted data points
        // When there are more then this, a log function is used to select points preferring the most recent

        int style = 1;

        int segMin = 10;
        int segMax = 17;

        double fontMin = 50;
        double fontMax = 65;

        int height = 60;
        double border = 0.5;

        double segWidth;
        String css;

        if (style == 1) {
            segWidth = 6;
            fontMin = 55;
            fontMax = 68;
            css = ".wr{height:%spx;position:relative;border:1px solid#aaa;background-color:#fff;text-align:center}" +
                    ".wr div{width:%s%%;position:absolute;background-color:#bbb;color:#000;height:2px}";
        } else if (style == 2) {
            segWidth = 8;
            fontMin = 55;
            fontMax = 70;
            css = ".wr{height:%spx;position:relative;border:1px solid#aaa;background-color:#fff;text-align:center}" +
                    ".wr div{width:%s%%;position:absolute;background-color:#aaa2;color:#000;line-height:120%%;border-radius:10px}";
        } else {
            segWidth = 7;
            css = ".wr{height:%spx;position:relative;border:1px solid#aaa;background-color:#fff;text-align:center}" +
                    ".wr div{width:%s%%;position:absolute;background-color:#ddd;color:#000;bottom:0}";
        }

        int total = calibrations.length;

        int seg = total < segMin ? segMin : (total > segMax ? segMax : total);
        int count = total < seg ? total : seg;

        double xadj = ((((100.0 - (segMin * segWidth)) / segMin) / 2) / (segMax - segMin)) * (segMax - seg);

        double ymax = 100 - (border * 2);
        double xmax = 100 - ((border + xadj) * 2);
        double xpos = border + xadj;
        double xadd = (xmax - segWidth) / (seg - 1);
        double font = fontMax - (((fontMax - fontMin) / (segMax - segMin)) * (seg - segMin));

        double scale = 1.5;
        double smid = 50;
        double vmin = 22;
        double vmax = 97;
        double vmid = 42;

        DecimalFormat dfFacLocal = new DecimalFormat("0", DecimalFormatSymbols.getInstance(Locale.getDefault()));
        dfFacLocal.setMinimumFractionDigits(0);
        dfFacLocal.setMaximumFractionDigits(1);

        DecimalFormat dfFac = new DecimalFormat("0", DecimalFormatSymbols.getInstance(Locale.ENGLISH));
        dfFac.setMinimumFractionDigits(0);
        dfFac.setMaximumFractionDigits(1);

        DecimalFormat dfNum = new DecimalFormat("0");
        dfNum.setMinimumFractionDigits(0);
        dfNum.setMaximumFractionDigits(0);

        StringBuilder parts = new StringBuilder();

        double v, r, l, p;

        for (int i = 0; i < count; i++) {

            l = Math.log10((i + 1) * (100 / seg));
            p = i + ((l * (total - count)) / 2);

            v = calibrations[(int) Math.round(p)] & 0xFF; // cal factor as 8bit div 10
            if (v > 100) v = 10 * (int) (v / 10); // keep cal factors > 10 as integers due to html space limitations

            r = vmid + ((v - smid) * scale);
            r = r < vmin ? vmin : (r > vmax ? vmax : r);

            parts.append(String.format("<div style='left:%s%%;top:%s%%'>%s</div>",
                    dfFac.format(xpos),
                    dfNum.format(100 - ((ymax * r) / 100)),
                    dfFacLocal.format(v / 10)));

            xpos += xadd;
        }

        return String.format("<style>" + css + "</style><div class='wr'style='font-size:%s%%'>%s</div>",
                dfNum.format(height),
                dfFac.format(segWidth),
                dfNum.format(font),
                parts.toString());
    }
 
/**
 * Creates a new instance of {@link MonetaryAmountDecimalFormatBuilder} with {@link Locale} set from parameter and pattern to format the {@link javax.money.MonetaryAmount}.
 * @param  pattern the pattern to be used
 * @param  locale the target locale
 * @see DecimalFormat
 * @see DecimalFormat#DecimalFormat(String)
 * @return a new instance of {@link MonetaryAmountDecimalFormatBuilder}
 */
public static MonetaryAmountDecimalFormatBuilder of(String pattern, Locale locale) {
    MonetaryAmountDecimalFormatBuilder builder = new MonetaryAmountDecimalFormatBuilder();
    builder.decimalFormat = new DecimalFormat(pattern, DecimalFormatSymbols.getInstance(locale));
    builder.locale = locale;
    return builder;
}