Java Code Examples for java.text.NumberFormat#getNumberInstance()

The following examples show how to use java.text.NumberFormat#getNumberInstance() . 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: Slic3rPrints.java    From BowlerStudio with GNU General Public License v3.0 5 votes vote down vote up
public NumberFormat getNumFormat(int numInts, int numDec){
	NumberFormat x = NumberFormat.getNumberInstance();
	x.setMaximumFractionDigits(numDec);
	x.setMinimumFractionDigits(numDec);
	x.setMaximumIntegerDigits(numInts);
	x.setMinimumIntegerDigits(numInts);
	return x;
}
 
Example 2
Source File: BigDecimalField.java    From robovm-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Default constructor. Returns a {@link BigDecimalField} with no number,
 * minValue and maxValue set, but stepwidth 1 and default
 * {@link NumberFormat}.
 */
public BigDecimalField() {
    super();
    setStyle(null);
    getStyleClass().add("big-decimal-field");
    number = new SimpleObjectProperty<BigDecimal>(this, "number");
    stepwidth = new SimpleObjectProperty<BigDecimal>(this, "stepwidth", BigDecimal.ONE);
    maxValue = new SimpleObjectProperty<BigDecimal>(this, "maxValue");
    minValue = new SimpleObjectProperty<BigDecimal>(this, "minValue");
    format = new SimpleObjectProperty<NumberFormat>(this, "format", NumberFormat.getNumberInstance());
    promptText = new SimpleStringProperty(this, "promptText", "");
    setFocusTraversable(false);
}
 
Example 3
Source File: MonetaryUtil.java    From zap-android with MIT License 5 votes vote down vote up
private String formatAsBtcDisplayAmount(long value) {
    Locale loc = mContext.getResources().getConfiguration().locale;
    NumberFormat nf = NumberFormat.getNumberInstance(loc);
    DecimalFormat df = (DecimalFormat) nf;
    df.setMaximumFractionDigits(8);
    df.setMinimumIntegerDigits(1);
    df.setMaximumIntegerDigits(16);
    return df.format(value / 1e8);
}
 
Example 4
Source File: EditProgressFAResult.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 获取未批准字数的比例
 * @return	如25.00%
 */
public String getNotApprovedWordsRatio(){
	float ratio = (float)notApprovedWords / (notApprovedWords + approvedWords);
	NumberFormat format = NumberFormat.getNumberInstance();
	format.setMaximumFractionDigits(2);
	
	return format.format(ratio * 100) + "%";
}
 
Example 5
Source File: EngineeringNotationFunction.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
private NumberFormat createDecimalFormat( final boolean fixedSize, final int decimalPlaces, final int precision,
    final Locale locale ) {
  final NumberFormat format = NumberFormat.getNumberInstance( locale );
  format.setGroupingUsed( false );
  if ( fixedSize ) {
    format.setMinimumFractionDigits( Math.max( 0, precision - decimalPlaces - 1 ) );
  } else {
    format.setMinimumFractionDigits( precision );
  }
  return format;
}
 
Example 6
Source File: DecimalVTypeFormat.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
/** @return NumberFormat to use in this formatter */
protected NumberFormat initFormat()
{
    final NumberFormat format = NumberFormat.getNumberInstance();
    format.setMinimumFractionDigits(precision);
    format.setMaximumFractionDigits(precision);
    return format;
}
 
Example 7
Source File: DailyCalendar.java    From AsuraFramework with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a string representing the properties of the 
 * <CODE>DailyCalendar</CODE>
 * 
 * @return the properteis of the DailyCalendar in a String format
 */
public String toString() {
    NumberFormat numberFormatter = NumberFormat.getNumberInstance();
    numberFormatter.setMaximumFractionDigits(0);
    numberFormatter.setMinimumIntegerDigits(2);
    StringBuffer buffer = new StringBuffer();
    buffer.append("base calendar: [");
    if (getBaseCalendar() != null) {
        buffer.append(getBaseCalendar().toString());
    } else {
        buffer.append("null");
    }
    buffer.append("], time range: '");
    buffer.append(numberFormatter.format(rangeStartingHourOfDay));
    buffer.append(":");
    buffer.append(numberFormatter.format(rangeStartingMinute));
    buffer.append(":");
    buffer.append(numberFormatter.format(rangeStartingSecond));
    buffer.append(":");
    numberFormatter.setMinimumIntegerDigits(3);
    buffer.append(numberFormatter.format(rangeStartingMillis));
    numberFormatter.setMinimumIntegerDigits(2);
    buffer.append(" - ");
    buffer.append(numberFormatter.format(rangeEndingHourOfDay));
    buffer.append(":");
    buffer.append(numberFormatter.format(rangeEndingMinute));
    buffer.append(":");
    buffer.append(numberFormatter.format(rangeEndingSecond));
    buffer.append(":");
    numberFormatter.setMinimumIntegerDigits(3);
    buffer.append(numberFormatter.format(rangeEndingMillis));
    buffer.append("', inverted: " + invertTimeRange + "]");
    return buffer.toString();
}
 
Example 8
Source File: NumberAxis.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a collection of tick units for integer values.
 * Uses a given Locale to create the DecimalFormats.
 *
 * @param locale the locale to use to represent Numbers.
 *
 * @return A collection of tick units for integer values.
 *
 * @see #setStandardTickUnits(TickUnitSource)
 */
public static TickUnitSource createIntegerTickUnits(Locale locale) {
    TickUnits units = new TickUnits();
    NumberFormat numberFormat = NumberFormat.getNumberInstance(locale);
    units.add(new NumberTickUnit(1, numberFormat, 2));
    units.add(new NumberTickUnit(2, numberFormat, 2));
    units.add(new NumberTickUnit(5, numberFormat, 5));
    units.add(new NumberTickUnit(10, numberFormat, 2));
    units.add(new NumberTickUnit(20, numberFormat, 2));
    units.add(new NumberTickUnit(50, numberFormat, 5));
    units.add(new NumberTickUnit(100, numberFormat, 2));
    units.add(new NumberTickUnit(200, numberFormat, 2));
    units.add(new NumberTickUnit(500, numberFormat, 5));
    units.add(new NumberTickUnit(1000, numberFormat, 2));
    units.add(new NumberTickUnit(2000, numberFormat, 2));
    units.add(new NumberTickUnit(5000, numberFormat, 5));
    units.add(new NumberTickUnit(10000, numberFormat, 2));
    units.add(new NumberTickUnit(20000, numberFormat, 2));
    units.add(new NumberTickUnit(50000, numberFormat, 5));
    units.add(new NumberTickUnit(100000, numberFormat, 2));
    units.add(new NumberTickUnit(200000, numberFormat, 2));
    units.add(new NumberTickUnit(500000, numberFormat, 5));
    units.add(new NumberTickUnit(1000000, numberFormat, 2));
    units.add(new NumberTickUnit(2000000, numberFormat, 2));
    units.add(new NumberTickUnit(5000000, numberFormat, 5));
    units.add(new NumberTickUnit(10000000, numberFormat, 2));
    units.add(new NumberTickUnit(20000000, numberFormat, 2));
    units.add(new NumberTickUnit(50000000, numberFormat, 5));
    units.add(new NumberTickUnit(100000000, numberFormat, 2));
    units.add(new NumberTickUnit(200000000, numberFormat, 2));
    units.add(new NumberTickUnit(500000000, numberFormat, 5));
    units.add(new NumberTickUnit(1000000000, numberFormat, 2));
    units.add(new NumberTickUnit(2000000000, numberFormat, 2));
    units.add(new NumberTickUnit(5000000000.0, numberFormat, 5));
    units.add(new NumberTickUnit(10000000000.0, numberFormat, 2));
    return units;
}
 
Example 9
Source File: SortaController.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Entity toDownloadRow(
    SortaJobExecution sortaJobExecution, Entity resultEntity, EntityType downloadEntityType) {
  NumberFormat format = NumberFormat.getNumberInstance();
  format.setMaximumFractionDigits(2);
  Entity inputEntity = resultEntity.getEntity(MatchingTaskContentMetaData.INPUT_TERM);
  Entity ontologyTermEntity =
      sortaService.getOntologyTermEntity(
          resultEntity.getString(MatchingTaskContentMetaData.MATCHED_TERM),
          sortaJobExecution.getOntologyIri());

  Entity row = new DynamicEntity(downloadEntityType);
  inputEntity
      .getAttributeNames()
      .forEach(
          attributeName -> {
            if (!attributeName.equalsIgnoreCase(SortaCsvRepository.ALLOWED_IDENTIFIER)) {
              row.set(attributeName, inputEntity.get(attributeName));
            }
          });
  if (ontologyTermEntity != null) {
    row.set(
        OntologyTermMetadata.ONTOLOGY_TERM_NAME,
        ontologyTermEntity.getString(OntologyTermMetadata.ONTOLOGY_TERM_NAME));
    row.set(
        OntologyTermMetadata.ONTOLOGY_TERM_IRI,
        ontologyTermEntity.getString(OntologyTermMetadata.ONTOLOGY_TERM_IRI));
  }
  row.set(
      MatchingTaskContentMetaData.VALIDATED,
      resultEntity.getBoolean(MatchingTaskContentMetaData.VALIDATED));
  row.set(
      MatchingTaskContentMetaData.REVIEW,
      resultEntity.getBoolean(MatchingTaskContentMetaData.REVIEW));

  Double score = resultEntity.getDouble(MatchingTaskContentMetaData.SCORE);
  if (score != null) {
    row.set(MatchingTaskContentMetaData.SCORE, format.format(score));
  }
  return row;
}
 
Example 10
Source File: SignificantFormat.java    From open-rmbt with Apache License 2.0 4 votes vote down vote up
public SignificantFormat(final int significantPlaces, final Locale locale)
{
    format = NumberFormat.getNumberInstance(locale);
    mathContext = new MathContext(significantPlaces, RoundingMode.HALF_UP);
}
 
Example 11
Source File: StandardXYToolTipGenerator.java    From opensim-gui with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a tool tip generator using default number formatters.
 */
public StandardXYToolTipGenerator() {
    this(DEFAULT_TOOL_TIP_FORMAT, NumberFormat.getNumberInstance(), 
            NumberFormat.getNumberInstance());
}
 
Example 12
Source File: HierarchicalTimingInfoFormatter.java    From ambiverse-nlu with Apache License 2.0 4 votes vote down vote up
public HierarchicalTimingInfoFormatter() {
  nf = NumberFormat.getNumberInstance(Locale.ENGLISH);
  nf.setMaximumFractionDigits(2);
}
 
Example 13
Source File: SelectorTester.java    From jenetics with Apache License 2.0 4 votes vote down vote up
/**
 * Print the list of histogram as CSV to the given writer.
 *
 * @param writer the print writer where the histograms are printed
 * @param parameters the selector creation parameters
 * @param histograms the histograms to print
 */
private static void print(
	final PrintStream writer,
	final Optimize opt,
	final List<Selector<?, ?>> selectors,
	final List<?> parameters,
	final List<Histogram<Double>> histograms,
	final int populationCount,
	final int loops
) {
	final NumberFormat format = NumberFormat.getNumberInstance(Locale.ENGLISH);
	format.setMinimumFractionDigits(15);
	format.setMaximumFractionDigits(15);

	printt(writer,
		"Creating selector distribution: %s",
		new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date())
	);
	printv(writer);

	println(writer, "# %-76s#", format("Selector distributions (opt=%s, npop=%d, loops=%d):", opt, populationCount, loops));
	for (Selector<?, ?> selector : selectors) {
		println(writer, "# %-76s#", format("   - %s", selector));
	}
	println(writer, "#=============================================================================#");

	final String header = parameters.stream()
		.map(Objects::toString)
		.collect(Collectors.joining(",", "", ""));

	writer.println();
	writer.println(header);

	final double[][] array = histograms.stream()
		.map(Histogram::getNormalizedHistogram)
		.toArray(double[][]::new);

	for (int i = 0; i < array[0].length; ++i) {
		for (int j = 0; j < array.length; ++j) {
			writer.print(format.format(array[j][i]));
			if (j < array.length - 1) {
				writer.print(',');
			}
		}
		writer.println();
	}
}
 
Example 14
Source File: StandardCrosshairLabelGenerator.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a new instance with default attributes.
 */
public StandardCrosshairLabelGenerator() {
    this("{0}", NumberFormat.getNumberInstance());
}
 
Example 15
Source File: WorkflowInstancesViewer.java    From oodt with Apache License 2.0 4 votes vote down vote up
private String formatWallClockMins(double wallClockMins) {
  NumberFormat fn = NumberFormat.getNumberInstance();
  fn.setMaximumFractionDigits(2);
  fn.setMinimumFractionDigits(2);
  return fn.format(wallClockMins);
}
 
Example 16
Source File: BubbleXYItemLabelGenerator.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates a new tool tip generator using default number formatters for the
 * x, y and z-values.
 */
public BubbleXYItemLabelGenerator() {
    this(DEFAULT_FORMAT_STRING, NumberFormat.getNumberInstance(),
            NumberFormat.getNumberInstance(),
            NumberFormat.getNumberInstance());
}
 
Example 17
Source File: AbstractStringToNumberConverter.java    From flow with Apache License 2.0 3 votes vote down vote up
/**
 * Returns the format used by
 * {@link #convertToPresentation(Object, ValueContext)} and
 * {@link #convertToModel(Object, ValueContext)}.
 *
 * @param locale
 *            The locale to use
 * @return A NumberFormat instance
 */
protected NumberFormat getFormat(Locale locale) {
    if (locale == null) {
        locale = Locale.getDefault();
    }

    return NumberFormat.getNumberInstance(locale);
}
 
Example 18
Source File: StandardPieSectionLabelGenerator.java    From ccu-historian with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Creates a new section label generator using the specified label format
 * string, and platform default number and percentage formatters.
 *
 * @param labelFormat  the label format (<code>null</code> not permitted).
 */
public StandardPieSectionLabelGenerator(String labelFormat) {
    this(labelFormat, NumberFormat.getNumberInstance(),
            NumberFormat.getPercentInstance());
}
 
Example 19
Source File: StandardPieSectionLabelGenerator.java    From buffer_bci with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Creates a new section label generator using the specified label format
 * string, and platform default number and percentage formatters.
 *
 * @param labelFormat  the label format (<code>null</code> not permitted).
 */
public StandardPieSectionLabelGenerator(String labelFormat) {
    this(labelFormat, NumberFormat.getNumberInstance(),
            NumberFormat.getPercentInstance());
}
 
Example 20
Source File: NumberAxis.java    From openstock with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Returns a collection of tick units for integer values.
 * Uses a given Locale to create the DecimalFormats.
 *
 * @param locale the locale to use to represent Numbers.
 *
 * @return A collection of tick units for integer values.
 *
 * @see #setStandardTickUnits(TickUnitSource)
 */
public static TickUnitSource createIntegerTickUnits(Locale locale) {
    NumberFormat numberFormat = NumberFormat.getNumberInstance(locale);
    return new NumberTickUnitSource(true, numberFormat);
}