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


Java NumberFormat.getNumberInstance方法代碼示例

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


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

示例1: write

import java.text.NumberFormat; //導入方法依賴的package包/類
public void write(PrintWriter printer, TimeSeries series) {

        Locale locale  = new Locale("en", "US");
        DecimalFormat formatter = (DecimalFormat)NumberFormat.getNumberInstance(locale);
        formatter.applyPattern("0.0000######");

        printer.print(String.format(header, series.getProperty("sensorid"), series.getLocation(), series.getProperty("position"), series.getSource(), series.getQuantityId(), series.getUnitId(),  series.getProperty("use") ));

        final double times[] = series.getTimesRef();
        final double values[] = series.getValuesRef();
        //TODO: detect order on read and use this order
        printer.println("datetime;value");
        String dateString;
        for (int i = 0; i < times.length; i++) {
            dateString = TimeUtils.mjdToString( times[i],this.datePattern);
            printer.println( dateString + this.delimiter + formatter.format(values[i]) );
        }
        printer.flush();
    }
 
開發者ID:OpenDA-Association,項目名稱:OpenDA,代碼行數:20,代碼來源:CsvTimeSeriesFormatter.java

示例2: prettyPrint

import java.text.NumberFormat; //導入方法依賴的package包/類
/**
 * Return a string with a table describing all tasks performed.
 * For custom reporting, call getTaskInfo() and use the task info directly.
 */
public String prettyPrint() {
    StringBuilder sb = new StringBuilder(shortSummary());
    sb.append('\n');
    if (!this.keepTaskList) {
        sb.append("No task info kept");
    } else {
        sb.append("-----------------------------------------\n");
        sb.append("ms     %     Task name\n");
        sb.append("-----------------------------------------\n");
        NumberFormat nf = NumberFormat.getNumberInstance(Locale.ROOT);
        nf.setMinimumIntegerDigits(5);
        nf.setGroupingUsed(false);
        NumberFormat pf = NumberFormat.getPercentInstance(Locale.ROOT);
        pf.setMinimumIntegerDigits(3);
        pf.setGroupingUsed(false);
        for (TaskInfo task : taskInfo()) {
            sb.append(nf.format(task.getTime().millis())).append("  ");
            sb.append(pf.format(task.getTime().secondsFrac() / totalTime().secondsFrac())).append("  ");
            sb.append(task.getTaskName()).append("\n");
        }
    }
    return sb.toString();
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:28,代碼來源:StopWatch.java

示例3: toString

import java.text.NumberFormat; //導入方法依賴的package包/類
@Override
public String toString() {
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
    NumberFormat nf = NumberFormat.getNumberInstance();
    nf.setMaximumFractionDigits(4);
    nf.setGroupingUsed(false);

    StringBuilder sb = new StringBuilder();

    sb.append("Date: ").append(date.format(formatter)).append(", ");
    sb.append("Total NAV: ").append(nf.format(totalNav)).append(", ");
    sb.append("Share price: ").append(nf.format(sharePrice)).append(", ");
    sb.append("Total shares: ").append(nf.format(getTotalShares()));

    return sb.toString();
}
 
開發者ID:ivandavidov,項目名稱:baud,代碼行數:17,代碼來源:BaudEntryDay.java

示例4: 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);
}
 
開發者ID:iedadata,項目名稱:geomapapp,代碼行數:32,代碼來源:RenderingTools.java

示例5: getNf

import java.text.NumberFormat; //導入方法依賴的package包/類
private static NumberFormat getNf(Locale locale) {
	NumberFormat nf = null;
	if (locale == null) {
		nf = NumberFormat.getNumberInstance();
	} else {
		nf = NumberFormat.getNumberInstance(locale);
	}
	nf.setGroupingUsed(false);
	return nf;
}
 
開發者ID:tb544731152,項目名稱:iBase4J,代碼行數:11,代碼來源:TypeParseUtil.java

示例6: setFileSizeSave

import java.text.NumberFormat; //導入方法依賴的package包/類
public void setFileSizeSave(long size){
	NumberFormat nf=NumberFormat.getNumberInstance() ; 
	nf.setMaximumFractionDigits(2);
	if(size<1024){
		fileSize =nf.format(size) +"B";
	}else if(size<1024*1024){
		this.fileSize =nf.format(size/1024.0) + "KB";
	}else if(size<1024*1024*1024){
		this.fileSize = nf.format(size/1024.0 * 1024) + "MB";
	}else if(size<1024*1024*1024*1024){
		this.fileSize = nf.format(size/1024.0 * 1024 * 1024) + "GB";
	}	
}
 
開發者ID:ranji1221,項目名稱:lemcloud,代碼行數:14,代碼來源:BackupDatabaseInfo.java

示例7: MonthDateFormat

import java.text.NumberFormat; //導入方法依賴的package包/類
/**
 * Creates a new formatter.
 * 
 * @param zone  the time zone used to extract the month and year from dates
 *              passed to this formatter (<code>null</code> not permitted).
 * @param locale  the locale used to determine the month names 
 *                (<code>null</code> not permitted).
 * @param chars  the maximum number of characters to use from the month 
 *               names, or zero to indicate that the entire month name 
 *               should be used.
 * @param showYear  an array of flags that control whether or not the
 *                  year is displayed for a particular month.
 * @param yearFormatter  the year formatter.
 */
public MonthDateFormat(TimeZone zone, Locale locale, int chars, 
                       boolean[] showYear, DateFormat yearFormatter) {
    if (locale == null) {
        throw new IllegalArgumentException("Null 'locale' argument.");
    }
    DateFormatSymbols dfs = new DateFormatSymbols(locale);
    String[] monthsFromLocale = dfs.getMonths();
    this.months = new String[12];
    for (int i = 0; i < 12; i++) {
        if (chars > 0) {
            months[i] = monthsFromLocale[i].substring(0, 
                    Math.min(chars, monthsFromLocale[i].length()));
        }
        else {
            months[i] = monthsFromLocale[i];
        }
    }
    this.calendar = new GregorianCalendar(zone);
    this.showYear = showYear;
    this.yearFormatter = yearFormatter; 
    
    // the following is never used, but it seems that DateFormat requires
    // it to be non-null.  It isn't well covered in the spec, refer to 
    // bug parade 5061189 for more info.
    this.numberFormat = NumberFormat.getNumberInstance();
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:41,代碼來源:MonthDateFormat.java

示例8: getFileColumnData

import java.text.NumberFormat; //導入方法依賴的package包/類
/**
 * Get the standard file column header information.
 * This default implementation is intended only for standard mode.
 * displayMode is specified in FormattedDisk.
 */
public List<String> getFileColumnData(int displayMode) {
	NumberFormat numberFormat = NumberFormat.getNumberInstance();
	List<String> list = new ArrayList<>();
	switch (displayMode) {
		case FormattedDisk.FILE_DISPLAY_NATIVE:
			list.add(isLocked() ? "*" : " "); //$NON-NLS-1$ //$NON-NLS-2$
			list.add(getFiletype());
			numberFormat.setMinimumIntegerDigits(3);
			list.add(numberFormat.format(getSectorsUsed()));
			list.add(getFilename());
			break;
		case FormattedDisk.FILE_DISPLAY_DETAIL:
			list.add(isLocked() ? "*" : " "); //$NON-NLS-1$ //$NON-NLS-2$
			list.add(getFiletype());
			list.add(getFilename());
			list.add(numberFormat.format(getSize()));
			numberFormat.setMinimumIntegerDigits(3);
			list.add(numberFormat.format(getSectorsUsed()));
			list.add(isDeleted() ? textBundle.get("Deleted") : "");  //$NON-NLS-1$//$NON-NLS-2$
			list.add("T" + getTrack() + " S" + getSector()); //$NON-NLS-1$ //$NON-NLS-2$
			break;
		default:	// FILE_DISPLAY_STANDARD
			list.add(getFilename());
			list.add(getFiletype());
			list.add(numberFormat.format(getSize()));
			list.add(isLocked() ? textBundle.get("Locked") : "");  //$NON-NLS-1$//$NON-NLS-2$
			break;
	}
	return list;
}
 
開發者ID:AppleCommander,項目名稱:AppleCommander,代碼行數:36,代碼來源:GutenbergFileEntry.java

示例9: parseValue

import java.text.NumberFormat; //導入方法依賴的package包/類
@Override
protected Double parseValue(String arg, Locale locale)
        throws IllegalOptionValueException {
  try {
    NumberFormat format = NumberFormat.getNumberInstance(locale);
    Number num = (Number) format.parse(arg);
    return new Double(num.doubleValue());
  } catch (ParseException e) {
    throw new IllegalOptionValueException(this, arg);
  }
}
 
開發者ID:RedTroop,項目名稱:Cubes,代碼行數:12,代碼來源:CmdLineParser.java

示例10: StandardXYToolTipGenerator

import java.text.NumberFormat; //導入方法依賴的package包/類
/**
 * Creates a tool tip generator using default number formatters.
 */
public StandardXYToolTipGenerator() {
    this(
        DEFAULT_TOOL_TIP_FORMAT,
        NumberFormat.getNumberInstance(), NumberFormat.getNumberInstance()
    );
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:10,代碼來源:StandardXYToolTipGenerator.java

示例11: formatNumber

import java.text.NumberFormat; //導入方法依賴的package包/類
public static String formatNumber(double number, int decimal, boolean grouping) {
	if (number >= 0) {
		NumberFormat n = NumberFormat.getNumberInstance();
		n.setGroupingUsed(grouping);
		if (decimal > 0) {
			n.setMinimumFractionDigits(decimal);
			n.setMaximumFractionDigits(decimal);
		}
		return n.format(number);
	} else {
		return "";
	}
}
 
開發者ID:max6cn,項目名稱:jmt,代碼行數:14,代碼來源:Formatter.java

示例12: toCsvString

import java.text.NumberFormat; //導入方法依賴的package包/類
public String toCsvString() {
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
    NumberFormat nf = NumberFormat.getNumberInstance();
    nf.setMaximumFractionDigits(4);
    nf.setGroupingUsed(false);

    StringBuilder sb = new StringBuilder();

    sb.append(date.format(formatter)).append(",");
    sb.append(nf.format(totalNav)).append(",");
    sb.append(nf.format(sharePrice)).append(",");
    sb.append(nf.format(getTotalShares()));

    return sb.toString();
}
 
開發者ID:ivandavidov,項目名稱:baud,代碼行數:16,代碼來源:BaudEntryDay.java

示例13: StandardXYItemLabelGenerator

import java.text.NumberFormat; //導入方法依賴的package包/類
/**
 * Creates an item label generator using default number formatters.
 */
public StandardXYItemLabelGenerator() {
    this(DEFAULT_ITEM_LABEL_FORMAT, NumberFormat.getNumberInstance(), 
            NumberFormat.getNumberInstance());
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:8,代碼來源:StandardXYItemLabelGenerator.java

示例14: BubbleXYItemLabelGenerator

import java.text.NumberFormat; //導入方法依賴的package包/類
/**
 * 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());
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:10,代碼來源:BubbleXYItemLabelGenerator.java

示例15: AbstractXYItemLabelGenerator

import java.text.NumberFormat; //導入方法依賴的package包/類
/**
 * Creates an item label generator using default number formatters.
 */
protected AbstractXYItemLabelGenerator() {
    this("{2}", NumberFormat.getNumberInstance(), 
            NumberFormat.getNumberInstance());
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:8,代碼來源:AbstractXYItemLabelGenerator.java


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