当前位置: 首页>>代码示例>>Java>>正文


Java NumberFormat.setMaximumFractionDigits方法代码示例

本文整理汇总了Java中java.text.NumberFormat.setMaximumFractionDigits方法的典型用法代码示例。如果您正苦于以下问题:Java NumberFormat.setMaximumFractionDigits方法的具体用法?Java NumberFormat.setMaximumFractionDigits怎么用?Java NumberFormat.setMaximumFractionDigits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.text.NumberFormat的用法示例。


在下文中一共展示了NumberFormat.setMaximumFractionDigits方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: convertByteTo

import java.text.NumberFormat; //导入方法依赖的package包/类
public String convertByteTo(long byteData){
	NumberFormat formatter = NumberFormat.getInstance();
	formatter.setMaximumFractionDigits(2);
	try {
		double kb = byteData/1024L;
		if(kb >= 1024){
			double mb = kb/1024L;
			if(mb >= 1024){
				double gb = mb/1024L;
				return formatter.format(gb) +" GB";
			}else
				return  formatter.format(mb)+" MB";
		}else{				
			return formatter.format(kb)+" KB";
		}

	} catch (Exception e) {
		// TODO: handle exception
		return String.valueOf(byteData);
	}
}
 
开发者ID:mityung,项目名称:XERUNG,代码行数:22,代码来源:Comman.java

示例2: bytes2String

import java.text.NumberFormat; //导入方法依赖的package包/类
public static String bytes2String(long sizeInBytes) {

        NumberFormat nf = new DecimalFormat();
        nf.setMaximumFractionDigits(1);
        nf.setMinimumFractionDigits(1);

        try {
            if (sizeInBytes < SPACE_KB) {
                return nf.format(sizeInBytes) + " Byte(s)";
            } else if (sizeInBytes < SPACE_MB) {
                return nf.format(sizeInBytes / SPACE_KB) + " KB";
            } else if (sizeInBytes < SPACE_GB) {
                return nf.format(sizeInBytes / SPACE_MB) + " MB";
            } else if (sizeInBytes < SPACE_TB) {
                return nf.format(sizeInBytes / SPACE_GB) + " GB";
            } else {
                return nf.format(sizeInBytes / SPACE_TB) + " TB";
            }
        } catch (Exception e) {
            return sizeInBytes + " Byte(s)";
        }

    }
 
开发者ID:lucasax,项目名称:Zero,代码行数:24,代码来源:Utils.java

示例3: nextAnchor

import java.text.NumberFormat; //导入方法依赖的package包/类
public String nextAnchor(Node node) {
    this.lastAnchorId++;
    NumberFormat format = NumberFormat.getNumberInstance();
    format.setMinimumIntegerDigits(3);
    format.setMaximumFractionDigits(0);// issue 172
    format.setGroupingUsed(false);
    String anchorId = format.format(this.lastAnchorId);
    return "id" + anchorId;
}
 
开发者ID:RoccoDev,项目名称:5zig-TIMV-Plugin,代码行数:10,代码来源:NumberAnchorGenerator.java

示例4: getFireAtTime

import java.text.NumberFormat; //导入方法依赖的package包/类
/**
 * Returns the fire time for the <CODE>NthIncludedDayTrigger</CODE> as a
 * string with the format &quot;HH:MM[:SS]&quot;, with HH representing the 
 * 24-hour clock hour of the fire time. Seconds are optional and their 
 * inclusion depends on whether or not they were provided to 
 * {@link #setFireAtTime(String)}. 
 * 
 * @return the fire time for the trigger
 * @see #setFireAtTime(String)
 */
public String getFireAtTime() {
    NumberFormat format = NumberFormat.getNumberInstance();
    format.setMaximumIntegerDigits(2);
    format.setMinimumIntegerDigits(2);
    format.setMaximumFractionDigits(0);
    
    return format.format(this.fireAtHour) + ":" + 
           format.format(this.fireAtMinute) + ":" +
           format.format(this.fireAtSecond);
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:21,代码来源:NthIncludedDayTrigger.java

示例5: MessageHandle

import java.text.NumberFormat; //导入方法依赖的package包/类
public static void MessageHandle(TelegramBot tgb, Update msg){
	MessageHandle.msg = msg;
	MessageHandle.tgb = tgb;	
	if(msg.getMessage().getFrom().getId() == 123078226){
		if(msg.hasMessage()){
			if(msg.getMessage().hasText()){					
				String line =  msg.getMessage().getText().replace(" ", "");
				Pattern r = Pattern.compile("\\-*[0-9]+\\.[0-9]+,\\-*[0-9]+\\.[0-9]+");
				if (r.matcher(line).find()) {
					String[] pinfo = line.split(",");
					try {
						double x,y;
						NumberFormat df = NumberFormat.getNumberInstance();
						df.setMaximumFractionDigits(6);
						x = Float.parseFloat(df.format(Float.parseFloat(pinfo[0])));
						y = Float.parseFloat(df.format(Float.parseFloat(pinfo[1])));
						findMon(Example.go.get(0),x,y);
					}catch(Exception ex){}
				}
				
				switch(msg.getMessage().getText().toUpperCase()){
					case "IV":
						showIV();
						break;
					case "GAMEID":
						showGameId();
						break;
				}
			}
		}
	}
	if(msg.getMessage().hasLocation()){
		findMon(Example.go.get(0),msg.getMessage().getLocation().getLatitude(),msg.getMessage().getLocation().getLongitude());
	}
}
 
开发者ID:slgphantom,项目名称:yearyearyear,代码行数:36,代码来源:MessageHandle.java

示例6: main

import java.text.NumberFormat; //导入方法依赖的package包/类
public static void main(String args[]) {

        StatisticsHandler h = new StatisticsHandler(System.out, null);
        NumberFormat nf = NumberFormat.getInstance();
        nf.setMaximumFractionDigits(2);
        nf.setMinimumFractionDigits(2);

        double d = h.getInstantValue("test", 1000, "105395052");
        d = h.getInstantValue("test", 6000, "105395986");
        System.out.println(nf.format(d));
    }
 
开发者ID:fast-data-transfer,项目名称:fdt,代码行数:12,代码来源:StatisticsHandler.java

示例7: benchmark

import java.text.NumberFormat; //导入方法依赖的package包/类
/**
 * This test runs a comparision of the performance of various string
 * formatting methods and validates that DoubleFormat is the fastest.
 * Not a replacement for in-depth analysis.
 *
 * If this test is failing, either DoubleFormat has a performance
 * regression or the built-in methods have improved enough to reconsider.
 *
 * The test can take multiple seconds to run.
 */
@Test
public void benchmark() throws Exception {
    final long iterations = 1000000;

    long duration_StringFormat = run_benchmark(iterations, (a) -> String.format("%.6f", a));

    NumberFormat javaFormatter = NumberFormat.getInstance();
    javaFormatter.setMinimumFractionDigits(0);
    javaFormatter.setMaximumFractionDigits(6);
    javaFormatter.setGroupingUsed(false);
    long duration_JavaFormat = run_benchmark(iterations, (a) -> javaFormatter.format(a));

    long duration_JavaStringBuilder = run_benchmark(iterations, (a) -> (new StringBuilder()).append(a));

    long duration_DoubleFormat = run_benchmark(iterations, (a) -> DoubleFormat.format(new StringBuilder(), a));

    System.out.println("DoubleFormat Performance comparison: " + iterations +" iterations");
    System.out.println("\tJava String.format: " + duration_StringFormat + " ms");
    System.out.println("\tJava NumberFormat:  " + duration_JavaFormat + " ms");
    System.out.println("\tJava StringBuilder: " + duration_JavaStringBuilder + " ms");
    System.out.println("\tDoubleFormat:       " + duration_DoubleFormat + " ms");

    assertTrue(duration_DoubleFormat < duration_StringFormat);
    assertTrue(duration_DoubleFormat < duration_JavaFormat);
    assertTrue(duration_DoubleFormat < duration_JavaStringBuilder);
}
 
开发者ID:awslabs,项目名称:swage,代码行数:37,代码来源:DoubleFormatTest.java

示例8: toString

import java.text.NumberFormat; //导入方法依赖的package包/类
/**
 * 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();
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:40,代码来源:DailyCalendar.java

示例9: getNumberFormat

import java.text.NumberFormat; //导入方法依赖的package包/类
@Override
public NumberFormat getNumberFormat(Class<? extends Number> numberType, int decimalPositions,
		boolean disableGrouping) {

	int decimals = decimalPositions;
	if (decimals < 0) {
		// use default, if any
		if (getLocalization() != null) {
			decimals = getLocalization().getDefaultDecimalPositions().orElse(-1);
		}
	}

	NumberFormat format = null;

	if (TypeUtils.isDecimalNumber(numberType)) {
		format = NumberFormat.getInstance(checkLocalized());
		if (decimals > -1) {
			format.setMinimumFractionDigits(decimals);
			format.setMaximumFractionDigits(decimals);
		}
	} else {
		format = NumberFormat.getIntegerInstance(checkLocalized());
	}

	if (disableGrouping) {
		format.setGroupingUsed(false);
	}
	return format;
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:30,代码来源:DefaultLocalizationContext.java

示例10: 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

示例11: initialValue

import java.text.NumberFormat; //导入方法依赖的package包/类
@Override
protected NumberFormat initialValue() {
	NumberFormat nf = new DecimalFormat("#0");
	nf = NumberFormat.getNumberInstance(Locale.US);
	nf.setMaximumFractionDigits(7);
	nf.setMinimumFractionDigits(7);
	nf.setRoundingMode(RoundingMode.HALF_UP);
	return nf;
}
 
开发者ID:GIScience,项目名称:openrouteservice,代码行数:10,代码来源:FormatUtility.java

示例12: renderNumber

import java.text.NumberFormat; //导入方法依赖的package包/类
/**
 * Renders a numeric value type Field
 * @param property Property to render
 * @return Field instance
 */
@SuppressWarnings("unchecked")
protected Field<T> renderNumber(Property<T> property) {
	// Number format

	Class<? extends Number> type = (Class<? extends Number>) property.getType();

	int decimals = property.getConfiguration().getParameter(StringValuePresenter.DECIMAL_POSITIONS).orElse(-1);
	boolean disableGrouping = property.getConfiguration().getParameter(StringValuePresenter.DISABLE_GROUPING)
			.orElse(Boolean.FALSE);

	Locale locale = LocalizationContext.getCurrent().filter(l -> l.isLocalized()).flatMap(l -> l.getLocale())
			.orElse(Locale.getDefault());

	NumberFormat numberFormat = LocalizationContext.getCurrent().filter(l -> l.isLocalized())
			.map((l) -> l.getNumberFormat(type, decimals, disableGrouping))
			.orElse(TypeUtils.isDecimalNumber(property.getType()) ? NumberFormat.getNumberInstance(locale)
					: NumberFormat.getIntegerInstance(locale));

	if (decimals > -1) {
		numberFormat.setMinimumFractionDigits(decimals);
		numberFormat.setMaximumFractionDigits(decimals);
	}
	if (disableGrouping) {
		numberFormat.setGroupingUsed(false);
	}

	return postProcessField(input.number(type).numberFormat(numberFormat).asField(), property);
}
 
开发者ID:holon-platform,项目名称:holon-vaadin7,代码行数:34,代码来源:DefaultFieldPropertyRenderer.java

示例13: getFileName

import java.text.NumberFormat; //导入方法依赖的package包/类
/**
 * get file name by offset
 *
 * @param offset file start offset
 * @return
 */
public static String getFileName(long offset) {
    NumberFormat nf = NumberFormat.getInstance();
    nf.setMinimumIntegerDigits(20);
    nf.setMaximumFractionDigits(0);
    nf.setGroupingUsed(false);
    return nf.format(offset);
}
 
开发者ID:taobaorun,项目名称:LiQ,代码行数:14,代码来源:FileUtil.java

示例14: start

import java.text.NumberFormat; //导入方法依赖的package包/类
@Override
    public void start(Stage stage) {

//Belgium	1950	8639369
//Belgium	1960	9118700
//Belgium	1970	9637800
//Belgium	1980	9846800
//Belgium	1990	9969310
//Belgium	2000	10263618
        double[][] input = {
            {1950, 8639369},
            {1960, 9118700},
            {1970, 9637800},
            {1980, 9846800},
            {1990, 9969310},
            {2000, 10263618}};
        double[] predictionYears = {1950, 1960, 1970, 1980, 1990, 2000, 2010, 2020, 2030, 2040};

        NumberFormat yearFormat = NumberFormat.getNumberInstance();
        yearFormat.setMaximumFractionDigits(0);
        yearFormat.setGroupingUsed(false);
        NumberFormat populationFormat = NumberFormat.getNumberInstance();
        populationFormat.setMaximumFractionDigits(0);
        
        SimpleRegression regression = new SimpleRegression();
        regression.addData(input);
        projectedSeries.setName("Projected");
        for (int i = 0; i < predictionYears.length; i++) {
            out.println(yearFormat.format(predictionYears[i]) + "-"
                    + populationFormat.format(regression.predict(predictionYears[i])));
            addDataItem(projectedSeries, predictionYears[i],
                    regression.predict(predictionYears[i]));
        }

        displayAttribute("Slope",regression.getSlope());
        displayAttribute("Intercept", regression.getIntercept());
        displayAttribute("InterceptStdEr", regression.getInterceptStdErr());
        displayAttribute("MeanSquareError", regression.getMeanSquareError());
        displayAttribute("N", + regression.getN());
        displayAttribute("R", + regression.getR());
        displayAttribute("RSquare", regression.getRSquare());

        //Create index chart
        stage.setTitle("Simple Linear Regression");
        xAxis.setTickLabelFormatter(new StringConverter<Number>() {
            @Override
            public String toString(Number object) {
                return (object.intValue()) + "";
            }

            @Override
            public Number fromString(String string) {
                return 0;
            }
        });

        final LineChart<Number, Number> lineChart
                = new LineChart<>(xAxis, yAxis);
        lineChart.setTitle("Belgium Population");
        yAxis.setLabel("Population");

        originalSeries.setName("Actual");
        addDataItem(originalSeries, 1950, 8639369);
        addDataItem(originalSeries, 1960, 9118700);
        addDataItem(originalSeries, 1970, 9637800);
        addDataItem(originalSeries, 1980, 9846800);
        addDataItem(originalSeries, 1990, 9969310);
        addDataItem(originalSeries, 2000, 10263618);

        Scene scene = new Scene(lineChart, 800, 600);
        lineChart.getData().addAll(originalSeries, projectedSeries);
        stage.setScene(scene);
        stage.show();
    }
 
开发者ID:PacktPublishing,项目名称:Java-for-Data-Science,代码行数:75,代码来源:MainApp - Simple Regression.java

示例15: currencyConverter

import java.text.NumberFormat; //导入方法依赖的package包/类
public static String currencyConverter(Double number) {
    NumberFormat numberFormat = NumberFormat.getCurrencyInstance(Locale.US);
    numberFormat.setMaximumFractionDigits(0);
    return numberFormat.format(number);
}
 
开发者ID:prakh25,项目名称:MovieApp,代码行数:6,代码来源:Utils.java


注:本文中的java.text.NumberFormat.setMaximumFractionDigits方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。