本文整理汇总了Java中java.text.NumberFormat.getIntegerInstance方法的典型用法代码示例。如果您正苦于以下问题:Java NumberFormat.getIntegerInstance方法的具体用法?Java NumberFormat.getIntegerInstance怎么用?Java NumberFormat.getIntegerInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.text.NumberFormat
的用法示例。
在下文中一共展示了NumberFormat.getIntegerInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getNumberFormatForLocale
import java.text.NumberFormat; //导入方法依赖的package包/类
/**
* Retrieves (possibly constructing) a NumberFormat configured for both the field constraints
* and the provided Locale.
* @param locale The locale to construct a number formatter for.
* @return A NumberFormat configured for both the field constraints and the Locale.
*/
public NumberFormat getNumberFormatForLocale(Locale locale) {
if (!hasPrecision()) {
return NumberFormat.getInstance(locale);
}
if (mIntegerPrecision) {
return NumberFormat.getIntegerInstance(locale);
}
String precisionStr = NAIVE_DECIMAL_FORMAT.format(mPrecision);
int decimalChar = precisionStr.indexOf('.');
if (decimalChar == -1) {
return NumberFormat.getIntegerInstance(locale);
}
int significantDigits = precisionStr.length() - decimalChar;
StringBuilder sb = new StringBuilder("0.");
char[] sigDigitsFormat = new char[significantDigits];
Arrays.fill(sigDigitsFormat, '#');
sb.append(sigDigitsFormat);
return new DecimalFormat(sb.toString(), new DecimalFormatSymbols(locale));
}
示例2: updateGridStatistics
import java.text.NumberFormat; //导入方法依赖的package包/类
private void updateGridStatistics() {
NumberFormat intFormat = NumberFormat.getIntegerInstance();
String infoDisplay = "Area (L, O, T) km\u00B2 :\t" +
intFormat.format(landArea) + "\t" +
intFormat.format(oceanArea) + "\t" +
intFormat.format(landArea + oceanArea) + "\n";
NumberFormat oneDec = NumberFormat.getNumberInstance();
oneDec.setMaximumFractionDigits(1);
String landMeanZstr = Float.isNaN(landMeanZ) ? "NaN" : oneDec.format(landMeanZ);
String oceanMeanZstr = Float.isNaN(oceanMeanZ) ? "NaN" : oneDec.format(oceanMeanZ);
String totalMeanZstr = Float.isNaN(totalMeanZ) ? "NaN" : oneDec.format(totalMeanZ);
infoDisplay += "Mean Elev (L, O, T) m :\t" +
landMeanZstr + "\t" +
oceanMeanZstr + "\t" +
totalMeanZstr + "\n";
String landSlopeMeanStr = Float.isNaN(landSlopeMean) ? "NaN" : oneDec.format(landSlopeMean);
String oceanSlopeMeanStr = Float.isNaN(oceanSlopeMean) ? "NaN" : oneDec.format(oceanSlopeMean);
String totalSlopeMeanStr = Float.isNaN(totalSlopeMean) ? "NaN" : oneDec.format(totalSlopeMean);
infoDisplay += "Mean Slope (L, O, T) \u00B0 :\t" +
landSlopeMeanStr + "\t" +
oceanSlopeMeanStr + "\t" +
totalSlopeMeanStr;
gridStatistics.setText(infoDisplay);
}
示例3: GridEditPanel
import java.text.NumberFormat; //导入方法依赖的package包/类
public GridEditPanel(int rasterSize) {
JLabel lblSize = new JLabel("size (px)");
lblSize.setFont(Program.TEXT_FONT.deriveFont(Font.BOLD).deriveFont(10f));
textField = new JFormattedTextField(NumberFormat.getIntegerInstance());
textField.setText("16");
textField.setFont(Program.TEXT_FONT.deriveFont(10f));
textField.setColumns(10);
textField.setValue(rasterSize);
GroupLayout groupLayout = new GroupLayout(this);
groupLayout.setHorizontalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addContainerGap()
.addComponent(lblSize, GroupLayout.PREFERRED_SIZE, 44, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(textField, GroupLayout.DEFAULT_SIZE, 166, Short.MAX_VALUE)
.addGap(34)));
groupLayout.setVerticalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addContainerGap()
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(lblSize, GroupLayout.PREFERRED_SIZE, 13, GroupLayout.PREFERRED_SIZE)
.addComponent(textField, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE))
.addContainerGap(46, Short.MAX_VALUE)));
setLayout(groupLayout);
}
示例4: ResultsPanel
import java.text.NumberFormat; //导入方法依赖的package包/类
public ResultsPanel() {
setLayout(new BorderLayout());
intFormat = NumberFormat.getIntegerInstance();
intFormat.setGroupingUsed(true);
percentFormat = NumberFormat.getPercentInstance();
percentFormat.setMaximumFractionDigits(1);
percentFormat.setMinimumFractionDigits(0);
}
示例5: init
import java.text.NumberFormat; //导入方法依赖的package包/类
@Override
public void init() throws OperatorException {
int localeIndex = getParameterAsInt(PARAMETER_LOCALE);
Locale selectedLocale = Locale.US;
if ((localeIndex >= 0) && (localeIndex < availableLocales.size())) {
selectedLocale = availableLocales.get(getParameterAsInt(PARAMETER_LOCALE));
}
int formatType = getParameterAsInt(PARAMETER_FORMAT_TYPE);
switch (formatType) {
case FORMAT_TYPE_NUMBER:
this.numberFormat = NumberFormat.getNumberInstance(selectedLocale);
break;
case FORMAT_TYPE_INTEGER:
this.numberFormat = NumberFormat.getIntegerInstance(selectedLocale);
break;
case FORMAT_TYPE_CURRENCY:
this.numberFormat = NumberFormat.getCurrencyInstance(selectedLocale);
break;
case FORMAT_TYPE_PERCENT:
this.numberFormat = NumberFormat.getPercentInstance(selectedLocale);
break;
case FORMAT_TYPE_PATTERN:
String formatString = getParameterAsString(PARAMETER_PATTERN);
// the following line only works for Java Versions >= 6
// this.numberFormat = new DecimalFormat(formatString,
// DecimalFormatSymbols.getInstance(selectedLocale));
this.numberFormat = new DecimalFormat(formatString, new DecimalFormatSymbols(selectedLocale));
break;
}
this.numberFormat.setGroupingUsed(getParameterAsBoolean(PARAMETER_USE_GROUPING));
}
示例6: setFormatLocale
import java.text.NumberFormat; //导入方法依赖的package包/类
public static void setFormatLocale(Locale locale) {
FORMAT_LOCALE = locale;
NUMBER_FORMAT = NumberFormat.getInstance(locale);
INTEGER_FORMAT = NumberFormat.getIntegerInstance(locale);
PERCENT_FORMAT = NumberFormat.getPercentInstance(locale);
FORMAT_SYMBOLS = new DecimalFormatSymbols(locale);
}
示例7: IntegerEditor
import java.text.NumberFormat; //导入方法依赖的package包/类
public IntegerEditor(int min, int max) {
super(new JFormattedTextField());
ftf = (JFormattedTextField) getComponent();
minimum = new Integer(min);
maximum = new Integer(max);
// Set up the editor for the integer cells.
integerFormat = NumberFormat.getIntegerInstance();
NumberFormatter intFormatter = new NumberFormatter(integerFormat);
intFormatter.setFormat(integerFormat);
intFormatter.setMinimum(minimum);
intFormatter.setMaximum(maximum);
ftf.setFormatterFactory(new DefaultFormatterFactory(intFormatter));
ftf.setValue(minimum);
ftf.setHorizontalAlignment(JTextField.TRAILING);
ftf.setFocusLostBehavior(JFormattedTextField.PERSIST);
// React when the user presses Enter while the editor is
// active. (Tab is handled as specified by
// JFormattedTextField's focusLostBehavior property.)
ftf.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "check");
ftf.getActionMap().put("check", new AbstractAction() {
public void actionPerformed(ActionEvent e) {
if (!ftf.isEditValid()) { // The text is invalid.
if (userSaysRevert()) { // reverted
ftf.postActionEvent(); // inform the editor
}
} else
try { // The text is valid,
ftf.commitEdit(); // so use it.
ftf.postActionEvent(); // stop editing
} catch (java.text.ParseException exc) {
}
}
});
}
示例8: ByteFormat
import java.text.NumberFormat; //导入方法依赖的package包/类
/**
* Construct a ByteFormat() instance with the default names[] array and min/max fraction digits.
*
* @since 1.0.0
*/
public ByteFormat() {
numberFormat = NumberFormat.getIntegerInstance();
names = new String[]{" GB", " MB", " KB", " byte"};
numberFormat.setMinimumFractionDigits(0);
numberFormat.setMaximumFractionDigits(1);
}
示例9: getNumberFormat
import java.text.NumberFormat; //导入方法依赖的package包/类
/**
* Gets the NumberFormat to use to convert values
* @param locale Locale to use
* @return the numberFormat If a NumberFormat was specified using {@link #setNumberFormat(NumberFormat)}, this one
* is returned. Otherwise, a NumberFormat is obtained using given Locale
*/
public NumberFormat getNumberFormat(Locale locale) {
Locale lcl = (locale != null) ? locale
: LocalizationContext.getCurrent().filter(l -> l.isLocalized()).flatMap(l -> l.getLocale())
.orElse(Locale.getDefault());
return (numberFormat != null) ? numberFormat
: TypeUtils.isDecimalNumber(numberType) ? NumberFormat.getNumberInstance(lcl)
: NumberFormat.getIntegerInstance(lcl);
}
示例10: formatTimeDiffereceFromSecondsToString
import java.text.NumberFormat; //导入方法依赖的package包/类
/**
* Convert duration in seconds to days, hours, minutes and seconds
* @param time time in seconds
* @return
*/
public static String formatTimeDiffereceFromSecondsToString( int time ) {
int days = time / DAY_IN_SECONDS;
time -= days * DAY_IN_SECONDS;
int hours = time / HOUR_IN_SECONDS;
time -= hours * HOUR_IN_SECONDS;
int minutes = time / MIN_IN_SECONDS;
time -= minutes * MIN_IN_SECONDS;
int seconds = time;
NumberFormat nf = NumberFormat.getIntegerInstance();
nf.setMinimumIntegerDigits(2);
StringBuilder duration = new StringBuilder();
if (days > 0) {
duration.append(days);
duration.append(" days, ");
}
duration.append(nf.format(hours));
duration.append(":");
duration.append(nf.format(minutes));
duration.append(":");
duration.append(nf.format(seconds));
return duration.toString();
}
示例11: setNumberRoll
import java.text.NumberFormat; //导入方法依赖的package包/类
/**
* Sets the number roll position.
*/
private void setNumberRoll(float number) {
mNumber = number;
int downNumber = (int) number;
int upNumber = downNumber + 1;
NumberFormat numberFormatter = NumberFormat.getIntegerInstance();
String newString = numberFormatter.format(upNumber);
if (!newString.equals(mUpNumber.getText().toString())) {
mUpNumber.setText(newString);
if (mContentDescriptionStringId != 0) {
mUpNumber.setContentDescription(getResources().getQuantityString(
mContentDescriptionStringId, upNumber, upNumber));
}
}
newString = numberFormatter.format(downNumber);
if (!newString.equals(mDownNumber.getText().toString())) {
mDownNumber.setText(newString);
if (mContentDescriptionStringId != 0) {
mDownNumber.setContentDescription(getResources().getQuantityString(
mContentDescriptionStringId, downNumber, downNumber));
}
}
float offset = number % 1.0f;
mUpNumber.setTranslationY(mUpNumber.getHeight() * (offset - 1.0f));
mDownNumber.setTranslationY(mDownNumber.getHeight() * offset);
mUpNumber.setAlpha(offset);
mDownNumber.setAlpha(1.0f - offset);
}
示例12: TestingGround
import java.text.NumberFormat; //导入方法依赖的package包/类
public TestingGround(BugReporter bugReporter) {
this.bugReporter = bugReporter;
if (active) {
formatter = NumberFormat.getIntegerInstance();
formatter.setMinimumIntegerDigits(4);
formatter.setGroupingUsed(false);
}
}
示例13: JSliderWithTextField
import java.text.NumberFormat; //导入方法依赖的package包/类
/**
* Full constructor.
*
* @param min the minimum value
* @param max the maximum value
* @param initialValue the initial value
* @param scale the scale factor between 0.0 and 1.0
* @param format the decimal format
*/
public JSliderWithTextField(int min, int max, int initialValue, double scale, NumberFormat format) {
this.min = min;
this.max = max;
GroupLayout layout = new GroupLayout(this);
this.setLayout(layout);
this.slider = new JSlider(JSlider.HORIZONTAL, min, max, initialValue);
this.slider.addChangeListener(this);
if (scale == 1.0) {
this.textField = new JFormattedTextField(NumberFormat.getIntegerInstance());
this.textField.setValue(initialValue);
} else {
this.textField = new JFormattedTextField(format);
this.textField.setValue(initialValue * scale);
}
this.textField.addPropertyChangeListener(this);
this.textField.addFocusListener(new SelectTextFocusListener(this.textField));
this.format = format;
this.scale = scale;
this.invScale = 1.0 / scale;
layout.setAutoCreateGaps(true);
layout.setHorizontalGroup(layout.createSequentialGroup().addComponent(this.slider)
.addComponent(this.textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
GroupLayout.PREFERRED_SIZE));
layout.setVerticalGroup(layout.createParallelGroup().addComponent(this.slider)
.addComponent(this.textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
GroupLayout.PREFERRED_SIZE));
}
示例14: testSearchStringMethodReferences
import java.text.NumberFormat; //导入方法依赖的package包/类
public void testSearchStringMethodReferences() throws CoreException {
// Wait for indexing end
waitUntilIndexesReady();
// Warm up
String name = "equals";
JavaSearchResultCollector resultCollector = new JavaSearchResultCollector();
search(name, METHOD, REFERENCES, resultCollector);
NumberFormat intFormat = NumberFormat.getIntegerInstance();
if (DACAPO_PRINT)
System.out.print(" " + intFormat.format(resultCollector.count) + " references for method '" + name + "' in workspace");
}
示例15: NumberFormatterFactory
import java.text.NumberFormat; //导入方法依赖的package包/类
public NumberFormatterFactory() {
super();
final NumberFormat format = NumberFormat.getIntegerInstance();
format.setGroupingUsed(false);
final NumberFormatter nf = new NumberFormatter(format);
setDefaultFormatter(nf);
setDisplayFormatter(nf);
setEditFormatter(nf);
}