java.text.DecimalFormatSymbols Java Examples

The following examples show how to use java.text.DecimalFormatSymbols. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AmountNumberTokenTest.java    From jsr354-ri with Apache License 2.0 6 votes vote down vote up
@Test
public void testParse_FR_with_NBSP_and_preset_decimal_symbols() {
    DecimalFormat decimalFormat = (DecimalFormat) NumberFormat.getCurrencyInstance(FRANCE);
    DecimalFormatSymbols syms = decimalFormat.getDecimalFormatSymbols();
    syms.setGroupingSeparator('\u00A0');

    testParse(FRANCE, PATTERN, syms, "12\u00A0345", 6, "int thousands", 12345.0, "12 345");
    testParse(FRANCE, PATTERN, syms, "-12\u00A0345", 7, "int thousands negative", -12345.0, "-12 345");
    testParse(FRANCE, PATTERN, syms, "12\u00A0345,6", 8, "float 1 thousands", 12345.6, "12 345,6");
    testParse(FRANCE, PATTERN, syms, "12\u00A0345,67", 9, "float 2 thousands", 12345.67, "12 345,67");
    testParse(FRANCE, PATTERN, syms, "12\u00A0345,678", 10, "float 3 thousands", 12345.678, "12 345,678");
    testParse(FRANCE, PATTERN, syms, "-12\u00A0345,6", 9, "float 1 thousands negative", -12345.6, "-12 345,6");
    testParse(FRANCE, PATTERN, syms, "-12\u00A0345,67", 10, "float 2 thousands negative", -12345.67, "-12 345,67");
    testParse(FRANCE, PATTERN, syms, "-12\u00A0345,678", 11, "float 3 thousands negative", -12345.678, "-12 345,678");
    testParse(FRANCE, PATTERN, syms, "-1\u00A0234\u00A0567,89", 13, "float 2 million negative", -1234567.89, "-1 234 567,89");
    testParse(FRANCE, PATTERN, syms, "\u00A0-1\u00A0234\u00A0567,89", 14, "float 2 million negative with leading space", -1234567.89, " -1 234 567,89");
    testParse(FRANCE, PATTERN, syms, "\u00A0-1\u00A0234\u00A0567,89\u00A0", 14, "float 2 million negative with leading and trailing space", -1234567.89, " -1 234 567,89 ");
}
 
Example #2
Source File: AnalysisDetails.java    From sonarqube-community-branch-plugin with GNU General Public License v3.0 6 votes vote down vote up
public static String format(QualityGate.Condition condition) {
    Metric<?> metric = CoreMetrics.getMetric(condition.getMetricKey());
    if (metric.getType() == Metric.ValueType.RATING) {
        return String
                .format("%s %s (%s %s)", Rating.valueOf(Integer.parseInt(condition.getValue())), metric.getName(),
                        condition.getOperator() == QualityGate.Operator.GREATER_THAN ? "is worse than" :
                        "is better than", Rating.valueOf(Integer.parseInt(condition.getErrorThreshold())));
    } else if (metric.getType() == Metric.ValueType.PERCENT) {
        NumberFormat numberFormat = new DecimalFormat("#0.00", DecimalFormatSymbols.getInstance(Locale.ENGLISH));
        return String.format("%s%% %s (%s %s%%)", numberFormat.format(new BigDecimal(condition.getValue())),
                             metric.getName(),
                             condition.getOperator() == QualityGate.Operator.GREATER_THAN ? "is greater than" :
                             "is less than", numberFormat.format(new BigDecimal(condition.getErrorThreshold())));
    } else {
        return String.format("%s %s (%s %s)", condition.getValue(), metric.getName(),
                             condition.getOperator() == QualityGate.Operator.GREATER_THAN ? "is greater than" :
                             "is less than", condition.getErrorThreshold());
    }
}
 
Example #3
Source File: MyCourseDetailAdapter.java    From ETSMobile-Android2 with Apache License 2.0 6 votes vote down vote up
public MyCourseDetailAdapter(final Context context, final ListeDesElementsEvaluation courseEvaluation, String cote) {
	super();
	this.courseEvaluation = courseEvaluation;
	this.cote = cote;
	nf_frCA = new DecimalFormat("##,#", new DecimalFormatSymbols(Locale.CANADA_FRENCH));
	nf_enUS = new DecimalFormat("##.#");
	// parse exams results
	for ( ElementEvaluation evaluationElement : courseEvaluation.liste) {
		if(evaluationElement.note !=null){
			if(evaluationElement.ignoreDuCalcul.equals("Non")){
				try {
					final String pond = evaluationElement.ponderation;
					final double value = nf_frCA.parse(pond).doubleValue();
					total += value;
					if(total>100){
						total = 100;
					}
				} catch (final ParseException e) {
				}
			}
		}
	}
	
	ctx = context;
	li = (LayoutInflater) ctx.getSystemService(inflater);
}
 
Example #4
Source File: TargetNodeNumeric.java    From openemm with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void setPrimaryValue(String tmpVal) {
       double tmpNum=0;
       if(this.primaryOperator==TargetNode.OPERATOR_IS.getOperatorCode()) {
           if(!tmpVal.equals("null") && !tmpVal.equals("not null")) {
               this.primaryValue = "null";
           } else {
               this.primaryValue=tmpVal;
           }
       } else {
           try {
               tmpNum=Double.parseDouble(tmpVal);
           } catch (Exception e) {
               if (logger.isInfoEnabled()) logger.info("Error in Number-Parsing: "+e);
           }
           DecimalFormat aFormat=new DecimalFormat("0.###########", new DecimalFormatSymbols(Locale.US));
           this.primaryValue=aFormat.format(tmpNum);
           // this.primaryValue=NumberFormat.getInstance(Locale.US).format(tmpNum);
           // this.primaryValue=Double.toString(tmpNum);
       }
   }
 
Example #5
Source File: AddXmlData.java    From hop with Apache License 2.0 6 votes vote down vote up
/**
   *
   */
public AddXmlData() {
  super();

  nf = NumberFormat.getInstance();
  df = (DecimalFormat) nf;
  dfs = new DecimalFormatSymbols();

  defaultDecimalFormat = (DecimalFormat) NumberFormat.getInstance();
  defaultDecimalFormatSymbols = new DecimalFormatSymbols();

  daf = new SimpleDateFormat();
  dafs = new DateFormatSymbols();

  defaultDateFormat = new SimpleDateFormat();
  defaultDateFormatSymbols = new DateFormatSymbols();

}
 
Example #6
Source File: NumberFormatProviderImpl.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #7
Source File: SWTUtil.java    From arx with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a pretty string representing the given double
 * @param value
 * @return
 */
public static String getPrettyString(double value) {
    DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.US);
    if (value == LN2) {
        return "ln(2)";
    } else if (value == LN3) {
        return "ln(3)";
    } else if (value == 0) {
        return "0";
    } else if (Math.abs(value) < 0.00001) {
        return new DecimalFormat("#.#####E0", symbols).format(value).replace('E', 'e');
    } else if (Math.abs(value) < 1) {
        return new DecimalFormat("#.#####", symbols).format(value);
    } else if (Math.abs(value) < 100000) {
        return new DecimalFormat("######.#####", symbols).format(value);
    } else {
        return String.valueOf(value).replace('E', 'e');
    }
}
 
Example #8
Source File: SendingCurrencyActivity.java    From guarda-android-wallets with GNU General Public License v3.0 6 votes vote down vote up
private void updateArrivalField() {
    if (amountToSend == null) return;
    if (isInclude) {
        BigDecimal amountDecimal = new BigDecimal(amountToSend);
        BigDecimal arrivalAmountDecimal = amountDecimal.subtract(currentFeeEth);
        if (arrivalAmountDecimal.compareTo(BigDecimal.ZERO) < 0) {
            arrivalAmountDecimal = BigDecimal.ZERO;
        }
        DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance();
        symbols.setDecimalSeparator('.');
        DecimalFormat decimalFormat = new DecimalFormat("###0.########", symbols);
        arrivalAmountToSend = decimalFormat.format(arrivalAmountDecimal);
        etArrivalAmount.setText(arrivalAmountToSend);
    } else {
        etArrivalAmount.setText(amountToSend);
    }
}
 
Example #9
Source File: LogTransferListener.java    From furnace with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void transferSucceeded(TransferEvent event)
{
   transferCompleted(event);
   TransferResource resource = event.getResource();
   long contentLength = event.getTransferredBytes();
   if (contentLength >= 0)
   {
      String type = (event.getRequestType() == TransferEvent.RequestType.PUT ? "Uploaded" : "Downloaded");
      String len = contentLength >= 1024 ? toKB(contentLength) + " KB" : contentLength + " B";

      String throughput = "";
      long duration = System.currentTimeMillis() - resource.getTransferStartTime();
      if (duration > 0)
      {
         DecimalFormat format = new DecimalFormat("0.0", new DecimalFormatSymbols(Locale.ENGLISH));
         double kbPerSec = (contentLength / 1024.0) / (duration / 1000.0);
         throughput = " at " + format.format(kbPerSec) + " KB/sec";
      }

      out.println(type + ": " + resource.getRepositoryUrl() + resource.getResourceName() + " (" + len
               + throughput + ")");
   }
}
 
Example #10
Source File: UserWalletFragment.java    From guarda-android-wallets with GNU General Public License v3.0 6 votes vote down vote up
private void showBalance() {
    networkManager.getBalance(walletManager.getWalletFriendlyAddress(), new Callback<BigDecimal>() {
        @Override
        public void onResponse(BigDecimal balance) {
            DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance();
            symbols.setDecimalSeparator('.');
            symbols.setGroupingSeparator(',');
            DecimalFormat decimalFormat = new DecimalFormat(ETH_SHOW_PATTERN, symbols);
            decimalFormat.setRoundingMode(RoundingMode.DOWN);
            if (balance != null && !balance.equals(new BigDecimal(0))) {
                curBalance = decimalFormat.format(balance);
                setCryptoBalance(curBalance);
                getLocalBalance(curBalance);
            }
        }
    });
}
 
Example #11
Source File: MavenUtil.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void transferSucceeded(TransferEvent event) {
    transferCompleted(event);

    TransferResource resource = event.getResource();
    long contentLength = event.getTransferredBytes();
    if (contentLength >= 0) {
        String type = (event.getRequestType() == TransferEvent.RequestType.PUT ? "Uploaded" : "Downloaded");
        String len = contentLength >= 1024 ? toKB(contentLength) + " KB" : contentLength + " B";

        String throughput = "";
        long duration = System.currentTimeMillis() - resource.getTransferStartTime();
        if (duration > 0) {
            DecimalFormat format = new DecimalFormat("0.0", new DecimalFormatSymbols(Locale.ENGLISH));
            double kbPerSec = (contentLength / 1024.0) / (duration / 1000.0);
            throughput = " at " + format.format(kbPerSec) + " KB/sec";
        }

        log.debug(type + ": " + resource.getRepositoryUrl() + resource.getResourceName() + " (" + len + throughput
                + ")");
    }
}
 
Example #12
Source File: AmountToSendActivity.java    From guarda-android-wallets with GNU General Public License v3.0 6 votes vote down vote up
private void updateEthBalance() {
    btnSend.setEnabled(false);
    mNetwonetworkManagerkManager.getBalance(walletManager.getWalletFriendlyAddress(), new Callback<BigDecimal>() {
        @Override
        public void onResponse(BigDecimal response) {
            btnSend.setEnabled(true);
            balance = response;
            DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance();
            symbols.setDecimalSeparator('.');
            symbols.setGroupingSeparator(',');
            DecimalFormat decimalFormat = new DecimalFormat(ETH_SHOW_PATTERN, symbols);
            decimalFormat.setRoundingMode(RoundingMode.DOWN);
            if (balance != null && !balance.equals(new BigDecimal(0))) {
                setCurrentBalance(decimalFormat.format(balance), sharedManager.getCurrentCurrency().toUpperCase());
            }
        }
    });
}
 
Example #13
Source File: ParsingFieldUpdateProcessorsTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void testParseDoubleNonRootLocale() throws Exception {
  final DecimalFormatSymbols fr_FR = DecimalFormatSymbols.getInstance(new Locale("fr","FR"));
  final char groupChar = fr_FR.getGroupingSeparator();
  final char decimalChar = fr_FR.getDecimalSeparator();

  double value = 10898.83491D;
  String doubleString1 = "10898"+decimalChar+"83491";
  String doubleString2 = "10"+groupChar+"898"+decimalChar+"83491";
  
  IndexSchema schema = h.getCore().getLatestSchema();
  assertNotNull(schema.getFieldOrNull("double_d")); // should match dynamic field "*_d"
  assertNull(schema.getFieldOrNull("not_in_schema"));
  SolrInputDocument d = processAdd("parse-double-french-no-run-processor",
                                   doc(f("id", "140"), f("double_d", doubleString1), 
                                       f("not_in_schema", doubleString2)));
  assertNotNull(d);
  assertThat(d.getFieldValue("double_d"), IS_DOUBLE);
  assertEquals(value, (Double)d.getFieldValue("double_d"), EPSILON);
  assertThat(d.getFieldValue("not_in_schema"), IS_DOUBLE);
  assertEquals(value, (Double)d.getFieldValue("not_in_schema"), EPSILON);
}
 
Example #14
Source File: LDIFInputData.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public LDIFInputData() {
  super();
  nrInputFields = -1;
  thisline = null;
  nextline = null;
  nf = NumberFormat.getInstance();
  df = (DecimalFormat) nf;
  dfs = new DecimalFormatSymbols();
  daf = new SimpleDateFormat();
  dafs = new DateFormatSymbols();

  nr_repeats = 0;
  filenr = 0;

  fr = null;
  zi = null;
  is = null;
  InputLDIF = null;
  recordLDIF = null;
  multiValueSeparator = ",";
  totalpreviousfields = 0;
  readrow = null;
  indexOfFilenameField = -1;
}
 
Example #15
Source File: NumberFormatProviderImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
            }
        }
    }
}
 
Example #16
Source File: TestShrinkAuxiliaryData.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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))
        );
    }
 
Example #17
Source File: LoggingTransferListener.java    From maven-repository-tools with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void transferSucceeded( TransferEvent event )
{
    transferCompleted( event );

    TransferResource resource = event.getResource();
    long contentLength = event.getTransferredBytes();
    if ( contentLength >= 0 )
    {
        String type = ( event.getRequestType() == TransferEvent.RequestType.PUT ? "Uploaded" : "Downloaded" );
        String len = contentLength >= 1024 ? toKB( contentLength ) + " KB" : contentLength + " B";

        String throughput = "";
        long duration = System.currentTimeMillis() - resource.getTransferStartTime();
        if ( duration > 0 )
        {
            long bytes = contentLength - resource.getResumeOffset();
            DecimalFormat format = new DecimalFormat( "0.0", new DecimalFormatSymbols( Locale.ENGLISH ) );
            double kbPerSec = ( bytes / 1024.0 ) / ( duration / 1000.0 );
            throughput = " at " + format.format( kbPerSec ) + " KB/sec";
        }

        logger.info( type + ": " + resource.getRepositoryUrl() + resource.getResourceName() + " (" + len
            + throughput + ")" );
    }
}
 
Example #18
Source File: NumberInterval.java    From brein-time-utilities with Apache License 2.0 6 votes vote down vote up
protected String unique(final double value) {
    if (MAX_DOUBLE < Math.abs(value)) {
        LOGGER.warn("Using double values larger than " + unique(MAX_DOUBLE));
    }

    if (value == Math.rint(value)) {
        return String.valueOf(Double.valueOf(value).longValue());
    } else {
        // http://stackoverflow.com/questions/16098046/
        // how-to-print-double-value-without-scientific-notation-using-java
        final DecimalFormat df = new DecimalFormat("0", DecimalFormatSymbols.getInstance(Locale.ENGLISH));
        df.setMaximumFractionDigits(340);

        return df.format(value);
    }
}
 
Example #19
Source File: TestRegexpRandom.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public void setUp() throws Exception {
  super.setUp();
  dir = newDirectory();
  RandomIndexWriter writer = new RandomIndexWriter(random(), dir,
      newIndexWriterConfig(new MockAnalyzer(random()))
      .setMaxBufferedDocs(TestUtil.nextInt(random(), 50, 1000)));
  
  Document doc = new Document();
  FieldType customType = new FieldType(TextField.TYPE_STORED);
  customType.setOmitNorms(true);
  Field field = newField("field", "", customType);
  doc.add(field);
  
  NumberFormat df = new DecimalFormat("000", new DecimalFormatSymbols(Locale.ROOT));
  for (int i = 0; i < 1000; i++) {
    field.setStringValue(df.format(i));
    writer.addDocument(doc);
  }
  
  reader = writer.getReader();
  writer.close();
  searcher = newSearcher(reader);
}
 
Example #20
Source File: LocationFormatterTest.java    From jpx with Apache License 2.0 5 votes vote down vote up
@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");
}
 
Example #21
Source File: TestDisjunctionMaxQuery.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
protected void printHits(String test, ScoreDoc[] h, IndexSearcher searcher)
    throws Exception {
  
  System.err.println("------- " + test + " -------");
  
  DecimalFormat f = new DecimalFormat("0.000000000", DecimalFormatSymbols.getInstance(Locale.ROOT));
  
  for (int i = 0; i < h.length; i++) {
    Document d = searcher.doc(h[i].doc);
    float score = h[i].score;
    System.err
        .println("#" + i + ": " + f.format(score) + " - " + d.get("id"));
  }
}
 
Example #22
Source File: CategoricalChartExpressionTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void assertTickUnitSizeByPattern( String pattern, double tickUnitSize) {
  NumberAxis axis = new NumberAxis();
  DecimalFormat formatter = new DecimalFormat( pattern,  new DecimalFormatSymbols(new Locale( "en_US" ) ) );
  expression.standardTickUnitsApplyFormat( axis, formatter );
  final TickUnits standardTickUnits = (TickUnits)axis.getStandardTickUnits();
  // first n standard tick unit elements should be removed
  Assert.assertEquals( tickUnitSize, standardTickUnits.get( 0 ).getSize(), 0.0000000001 );
}
 
Example #23
Source File: IndexSplitter.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@SuppressForbidden(reason = "System.out required: command line tool")
public void listSegments() throws IOException {
  DecimalFormat formatter = new DecimalFormat("###,###.###", DecimalFormatSymbols.getInstance(Locale.ROOT));
  for (int x = 0; x < infos.size(); x++) {
    SegmentCommitInfo info = infos.info(x);
    String sizeStr = formatter.format(info.sizeInBytes());
    System.out.println(info.info.name + " " + sizeStr);
  }
}
 
Example #24
Source File: DecimalFormatSymbolsTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * @tests java.text.DecimalFormatSymbols#equals(java.lang.Object)
 */
public void test_equalsLjava_lang_Object() {
    assertTrue("Equal objects returned false", dfs.equals(dfs.clone()));
    dfs.setDigit('B');
    assertTrue("Un-Equal objects returned true", !dfs
            .equals(new DecimalFormatSymbols()));

}
 
Example #25
Source File: CustomEditTextWatcher.java    From ShoppingList with MIT License 5 votes vote down vote up
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;
}
 
Example #26
Source File: DoubleTools.java    From JANNLab with GNU General Public License v3.0 5 votes vote down vote up
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);    
}
 
Example #27
Source File: ParseBigDecimalTest.java    From robe with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void constructorTests() throws Exception {
    new ParseBigDecimal(DecimalFormatSymbols.getInstance());
    new ParseBigDecimal(new Optional());
    new ParseBigDecimal(DecimalFormatSymbols.getInstance(), new Optional());
    //No exception means success.

}
 
Example #28
Source File: PropertyInputData.java    From hop with Apache License 2.0 5 votes vote down vote up
public PropertyInputData() {
  super();
  previousRow = null;
  thisline = null;
  nf = NumberFormat.getInstance();
  df = (DecimalFormat) nf;
  dfs = new DecimalFormatSymbols();
  daf = new SimpleDateFormat();
  dafs = new DateFormatSymbols();

  nr_repeats = 0;
  previousRow = null;
  filenr = 0;

  fr = null;
  is = null;
  rw = null;
  totalpreviousfields = 0;
  indexOfFilenameField = -1;
  readrow = null;

  pro = null;
  it = null;
  iniSection = null;
  wini = null;
  itSection = null;
  realEncoding = null;
  realSection = null;
  propfiles = true;
  iniIt = null;
}
 
Example #29
Source File: DecimalFormatSymbolsTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * @tests java.text.DecimalFormatSymbols#getInstance()
 */
public void test_getInstance() {
    assertEquals(new DecimalFormatSymbols(), DecimalFormatSymbols.getInstance());
    assertEquals(new DecimalFormatSymbols(Locale.getDefault()),
            DecimalFormatSymbols.getInstance());

    assertNotSame(DecimalFormatSymbols.getInstance(), DecimalFormatSymbols.getInstance());
}
 
Example #30
Source File: Formatter.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private char getZero(Locale l) {
    if ((l != null) &&  !l.equals(locale())) {
        DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(l);
        return dfs.getZeroDigit();
    }
    return zero;
}