當前位置: 首頁>>代碼示例>>Java>>正文


Java NumberFormat.getInstance方法代碼示例

本文整理匯總了Java中java.text.NumberFormat.getInstance方法的典型用法代碼示例。如果您正苦於以下問題:Java NumberFormat.getInstance方法的具體用法?Java NumberFormat.getInstance怎麽用?Java NumberFormat.getInstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.text.NumberFormat的用法示例。


在下文中一共展示了NumberFormat.getInstance方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getDecimalFormat

import java.text.NumberFormat; //導入方法依賴的package包/類
/**
 * Make an instance of DecimalFormat.
 *
 * @param locale The locale
 * @param pattern The pattern is used for the convertion
 * @return The format for the locale and pattern
 *
 * @throws ConversionException if conversion cannot be performed
 *  successfully
 * @throws ParseException if an error occurs parsing a String to a Number
 */
private DecimalFormat getDecimalFormat(final Locale locale, final String pattern) {

    final DecimalFormat numberFormat = (DecimalFormat) NumberFormat.getInstance(locale);

    // if some constructors default pattern to null, it makes only sense to handle null pattern gracefully
    if (pattern != null) {
        if (locPattern) {
            numberFormat.applyLocalizedPattern(pattern);
        } else {
            numberFormat.applyPattern(pattern);
        }
    } else {
        log.debug("No pattern provided, using default.");
    }

    return numberFormat;
}
 
開發者ID:yippeesoft,項目名稱:NotifyTools,代碼行數:29,代碼來源:StringLocaleConverter.java

示例2: setZoomHistoryNext

import java.text.NumberFormat; //導入方法依賴的package包/類
public void setZoomHistoryNext(XMap mapSource) {
	Rectangle2D r = null;
	r = mapSource.getClipRect2D();
	Point2D.Double p2 = new Point2D.Double(
			r.getX()+.5*r.getWidth(),
			r.getY()+.5*r.getHeight() );
	p2 = (Point2D.Double)mapSource.getProjection().getRefXY(p2);

	double zoom = mapSource.getZoom();
	NumberFormat fmtZoom1 = NumberFormat.getInstance();
	fmtZoom1.setMinimumFractionDigits(1);
	fmtZoom1.format(zoom);

	nextZoom = "next, " + p2.getX() + ", " + p2.getY() + ", " + zoom;
	zoomActionTrack.selectAll();
	zoomActionTrack.replaceSelection(nextZoom);
	//System.out.println("track: " + zoomActionTrack.getText());
}
 
開發者ID:iedadata,項目名稱:geomapapp,代碼行數:19,代碼來源:XMap.java

示例3: getLocalisedDouble

import java.text.NumberFormat; //導入方法依賴的package包/類
/**
    * Convert a string back into a Float. Assumes string was formatted using formatLocalisedNumber originally. Should
    * ensure that it is using the same locale/number format as when it was formatted. If no locale is suppied, it will
    * use the server's locale.
    *
    * Need to strip out any spaces as spaces are valid group separators in some European locales (e.g. Polish) but they
    * seem to come back from Firefox as a plain space rather than the special separating space.
    */
   public static Double getLocalisedDouble(String inputStr, Locale locale) {
String numberStr = inputStr;
if (numberStr != null) {
    numberStr = numberStr.replace(" ", "");
}
if ((numberStr != null) && (numberStr.length() > 0)) {
    Locale useLocale = locale != null ? locale : NumberUtil.getServerLocale();
    NumberFormat format = NumberFormat.getInstance(useLocale);
    ParsePosition pp = new ParsePosition(0);
    Number num = format.parse(numberStr, pp);
    if ((num != null) && (pp.getIndex() == numberStr.length())) {
	return num.doubleValue();
    }
}
throw new NumberFormatException("Unable to convert number " + numberStr + "to double using locale "
	+ locale.getCountry() + " " + locale.getLanguage());
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:26,代碼來源:NumberUtil.java

示例4: getSuccessPercentageForSuite

import java.text.NumberFormat; //導入方法依賴的package包/類
public String getSuccessPercentageForSuite()
{
    String successPercentageForSuite = "";

    NumberFormat nf = NumberFormat.getInstance();

    nf.setMaximumFractionDigits(2);
    nf.setGroupingUsed(true);

    try
    {
        successPercentageForSuite = nf
                .format(((float) getTotalPassedMethodsForSuite() / (float) (getTotalPassedMethodsForSuite()
                        + getTotalFailedMethodsForSuite() + getTotalSkippedMethodsForSuite())) * 100);
    } catch (NumberFormatException realCause)
    {
        LOGGER.debug(realCause.getMessage());
    }

    return successPercentageForSuite;
}
 
開發者ID:pradeeptaswain,項目名稱:oldmonk,代碼行數:22,代碼來源:ReporterAPI.java

示例5: updateTotalDistance

import java.text.NumberFormat; //導入方法依賴的package包/類
@Override
public void updateTotalDistance(Context context) {
    if(context != null){
        SharedPreferences sp = context.getSharedPreferences(RMConfiguration.FILE_CONFIG, Context.MODE_PRIVATE);
        long distance = sp.getLong(RMConfiguration.KEY_TOTAL_DISTANCE,0);
        long tmpDistance = sp.getLong(RMConfiguration.KEY_TMP_DISTANCE,0);
        if(tmpDistance < 0){
            return;
        }
        distance += tmpDistance;
        //if there have an effective value, update it now
        SharedPreferences.Editor editor = sp.edit();
        editor.putLong(RMConfiguration.KEY_TMP_DISTANCE,0);
        editor.putLong(RMConfiguration.KEY_TOTAL_DISTANCE,distance);
        editor.commit();
        DecimalFormat distanceFormater = (DecimalFormat) NumberFormat.getInstance();
        distanceFormater.setMinimumFractionDigits(2);
        distanceFormater.setMaximumFractionDigits(2);
        mFunctionFragment.showUpgradeDistance(distanceFormater.format(distance/1000.0));
    }
}
 
開發者ID:stdnull,項目名稱:RunMap,代碼行數:22,代碼來源:FunctionFragPresenterImpl.java

示例6: num2decStr

import java.text.NumberFormat; //導入方法依賴的package包/類
public static String num2decStr(double num, int digits) {
	NumberFormat nf = NumberFormat.getInstance(Locale.ENGLISH);
	nf.setMinimumFractionDigits(digits);
	nf.setMaximumFractionDigits(digits);
       String result = nf.format(num);		
	return result;
}
 
開發者ID:ferenc-hechler,項目名稱:RollenspielAlexaSkill,代碼行數:8,代碼來源:NumberUtil.java

示例7: handleResult

import java.text.NumberFormat; //導入方法依賴的package包/類
public void handleResult(Codec codec, Result result) {
    if (result.getError() != null) {
        result.getError().printStackTrace();
        return;
    }
    NumberFormat format = NumberFormat.getInstance();
    System.out.println(result.getName() + "\t" + codec.getName() + "\t" + format.format(result.getMillis()) + "\tYGC " + result.getYoungGC()
                       + "\tYGCT " + result.getYoungGCTime());
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:10,代碼來源:BenchmarkExecutor.java

示例8: getText

import java.text.NumberFormat; //導入方法依賴的package包/類
@Override
public String getText()
{
	final NumberFormat numberFormat = NumberFormat.getInstance(CurrentLocale.getLocale());
	if( minDecimals != null )
	{
		numberFormat.setMinimumFractionDigits(minDecimals);
	}
	if( maxDecimals != null )
	{
		numberFormat.setMaximumFractionDigits(maxDecimals);
	}
	return numberFormat.format(number);
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:15,代碼來源:NumberLabel.java

示例9: testLocalizationValues

import java.text.NumberFormat; //導入方法依賴的package包/類
private static int testLocalizationValues() {

        DecimalFormat df = (DecimalFormat)
            NumberFormat.getInstance(GoldenDoubleValues.FullLocalizationTestLocale);

        double[] localizationValues = GoldenDoubleValues.DecimalLocalizationValues;
        int size = localizationValues.length;
        int successCounter = 0;
        int failureCounter = 0;
        for (int i = 0; i < size; i++) {

            double d = localizationValues[i];
            String formatted = df.format(d);

            char[] expectedUnicodeArray =
                getCharsFromUnicodeArray(
                    GoldenFormattedValues.DecimalDigitsLocalizedFormattedValues[i]);
            String expected = new String(expectedUnicodeArray);

            if (!formatted.equals(expected)) {
                failureCounter++;
                System.out.println(
                    "--- Localization error for value d = " + d +
                    ". Exact value = " + new BigDecimal(d).toString() +
                    ". Expected result = " + expected +
                    ". Output result = " + formatted);
            } else successCounter++;
        }
        System.out.println("Checked positively " + successCounter +
                           " golden decimal values out of " + size +
                           " tests. There were " + failureCounter +
                           " format failure");

        return failureCounter;
    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:36,代碼來源:RoundingAndPropertyTest.java

示例10: parseFee

import java.text.NumberFormat; //導入方法依賴的package包/類
private static float parseFee(String managementFee) throws ComparisonException, ParseException {
    float fee;
    if (managementFee.contains(",")){
        NumberFormat format = NumberFormat.getInstance(Locale.FRANCE);
        Number number = format.parse(managementFee);
        fee = number.floatValue()/100;
    }
    else {
        fee = Float.parseFloat(managementFee)/100;
    }
    if (fee > 0.02 || fee < 0) throw new FeeSizeException("Fee size does not match Estonian standards");
    return fee;
}
 
開發者ID:TulevaEE,項目名稱:onboarding-service,代碼行數:14,代碼來源:EstonianFeeFinderService.java

示例11: XMLConsumer

import java.text.NumberFormat; //導入方法依賴的package包/類
public XMLConsumer(File fileName) throws IOException
{
    writer = new OutputStreamWriter(new FileOutputStream(fileName), "UTF-8");
    addAutoclose(this);
    writer.write("<benchmark-results tstamp=\"" + tstamp() + "\">\n\n");

    nf = NumberFormat.getInstance(Locale.ENGLISH);
    nf.setMaximumFractionDigits(3);
    nf.setGroupingUsed(false);            
}
 
開發者ID:adnanmitf09,項目名稱:Rubus,代碼行數:11,代碼來源:XMLConsumer.java

示例12: TvshowDetailedPresenter

import java.text.NumberFormat; //導入方法依賴的package包/類
public TvshowDetailedPresenter(Context context, ExtendedClickListener listener) {
    super(context, AdapterDefaultValuesDetails.INSTANCE, listener);
    mNumberFormat = NumberFormat.getInstance();
    mNumberFormat.setMinimumFractionDigits(1);
    mNumberFormat.setMaximumFractionDigits(1);
    mDateFormat = DateFormat.getDateInstance(DateFormat.LONG);
}
 
開發者ID:archos-sa,項目名稱:aos-Video,代碼行數:8,代碼來源:TvshowDetailedPresenter.java

示例13: TvshowListPresenter

import java.text.NumberFormat; //導入方法依賴的package包/類
public TvshowListPresenter(Context context, AdapterDefaultValues defaultValues,ExtendedClickListener listener) {
    super(context, defaultValues, listener);
    mNumberFormat = NumberFormat.getInstance();
    mNumberFormat.setMinimumFractionDigits(1);
    mNumberFormat.setMaximumFractionDigits(1);
    mDateFormat = DateFormat.getDateInstance(DateFormat.LONG);
}
 
開發者ID:archos-sa,項目名稱:aos-Video,代碼行數:8,代碼來源:TvshowListPresenter.java

示例14: getMeasuresRow

import java.text.NumberFormat; //導入方法依賴的package包/類
public List<String> getMeasuresRow(Object[] measures, String title) {
  List<AnnotationDiffer> differs = new ArrayList<AnnotationDiffer>(
    getDifferByTypeMap().values());
  AnnotationDiffer differ = new AnnotationDiffer(differs);
  NumberFormat f = NumberFormat.getInstance(Locale.ENGLISH);
  f.setMaximumFractionDigits(2);
  f.setMinimumFractionDigits(2);
  List<String> row = new ArrayList<String>();
  row.add(title);
  row.add(Integer.toString(differ.getCorrectMatches()));
  row.add(Integer.toString(differ.getMissing()));
  row.add(Integer.toString(differ.getSpurious()));
  row.add(Integer.toString(differ.getPartiallyCorrectMatches()));
  for (Object object : measures) {
    String measure = (String) object;
    double beta = Double.valueOf(
      measure.substring(1,measure.indexOf('-')));
    if (measure.endsWith("strict")) {
      row.add(f.format(differ.getPrecisionStrict()));
      row.add(f.format(differ.getRecallStrict()));
      row.add(f.format(differ.getFMeasureStrict(beta)));
    } else if (measure.endsWith("strict BDM")) {
      row.add(f.format(getPrecisionStrictBdm()));
      row.add(f.format(getRecallStrictBdm()));
      row.add(f.format(getFMeasureStrictBdm(beta)));
    } else if (measure.endsWith("lenient")) {
      row.add(f.format(differ.getPrecisionLenient()));
      row.add(f.format(differ.getRecallLenient()));
      row.add(f.format(differ.getFMeasureLenient(beta)));
    } else if (measure.endsWith("lenient BDM")) {
      row.add(f.format(getPrecisionLenientBdm()));
      row.add(f.format(getRecallLenientBdm()));
      row.add(f.format(getFMeasureLenientBdm(beta)));
    } else if (measure.endsWith("average")) {
      row.add(f.format(differ.getPrecisionAverage()));
      row.add(f.format(differ.getRecallAverage()));
      row.add(f.format(differ.getFMeasureAverage(beta)));
    } else if (measure.endsWith("average BDM")) {
      row.add(f.format(getPrecisionAverageBdm()));
      row.add(f.format(getRecallAverageBdm()));
      row.add(f.format(getFMeasureAverageBdm(beta)));
    }
  }
  return row;
}
 
開發者ID:GateNLP,項目名稱:gate-core,代碼行數:46,代碼來源:OntologyMeasures.java

示例15: determineDecimalSeparator

import java.text.NumberFormat; //導入方法依賴的package包/類
public void determineDecimalSeparator() {
    NumberFormat numberFormat = NumberFormat.getInstance();
    if (numberFormat instanceof DecimalFormat) {
        decimalSeparator = ((DecimalFormat) numberFormat).getDecimalFormatSymbols().getDecimalSeparator();
    }
}
 
開發者ID:huashengzzz,項目名稱:SmartChart,代碼行數:7,代碼來源:ValueFormatterHelper.java


注:本文中的java.text.NumberFormat.getInstance方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。