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


Java DecimalFormat.setRoundingMode方法代码示例

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


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

示例1: displayProbabilities

import java.text.DecimalFormat; //导入方法依赖的package包/类
private void displayProbabilities() {
    final DecimalFormatSymbols symbols = new DecimalFormatSymbols();
    symbols.setDecimalSeparator('.');
    symbols.setGroupingSeparator(',');
    final DecimalFormat df = new DecimalFormat("", symbols);
    df.setMaximumFractionDigits(1);
    df.setRoundingMode(RoundingMode.HALF_UP);
    df.setMinimumIntegerDigits(1);
    Map<HiddenPower, Double> hiddenPowers = hiddenPowerCalculator.computeHiddenPower(pokemon);
    double badHiddenPower = 0;
    for (final HiddenPower hiddenPower: HiddenPower.values()) {
        double probability = hiddenPowers.get(hiddenPower);
        hiddenPowerLabels.get(hiddenPower.ordinal()).setText(hiddenPower.getName() + ": " + df.format(probability * 100) + "%");
        if (hiddenPower.equals(HiddenPower.WATER) || hiddenPower.equals(HiddenPower.GRASS)) {
            badHiddenPower+= probability;
        }
    }
    feelsBadMan.setVisible(badHiddenPower >= 0.375);
}
 
开发者ID:wartab,项目名称:gen7-iv-calculator,代码行数:20,代码来源:HiddenPowerPresenter.java

示例2: getWeatherResponse

import java.text.DecimalFormat; //导入方法依赖的package包/类
@Override
public void getWeatherResponse(WeatherResponse weatherResponse) {
    if (weatherResponse.getWeatherItems() != null) {
        setWeatherWidgetImage(weatherResponse.getWeatherItems()[0].getIcon());
        weatherTextView.setText(weatherResponse.getWeatherItems()[0].getDescription());
        SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
        double currentTemp = weatherResponse.getTemperatureItem().getTemp();
        double maxTemp = weatherResponse.getTemperatureItem().getTempMax();
        double minTemp = weatherResponse.getTemperatureItem().getTempMin();
        if (sharedPreferences.getString("degrees_list", "ºC").equalsIgnoreCase("ºF")) {
            currentTemp = (currentTemp * 1.8) + 32;
            maxTemp = (maxTemp * 1.8) + 32;
            minTemp = (minTemp * 1.8) + 32;
        }
        DecimalFormat df = new DecimalFormat("#.#");
        df.setRoundingMode(RoundingMode.CEILING);
        tempTextView.setText(df.format(currentTemp) + sharedPreferences.getString("degrees_list", "ºC"));
        tempMaxTextView.setText(df.format(maxTemp) + sharedPreferences.getString("degrees_list", "ºC"));
        tempMinTextView.setText(df.format(minTemp) + sharedPreferences.getString("degrees_list", "ºC"));
    } else {
        weatherRelativeLayout.setVisibility(View.GONE);
    }
}
 
开发者ID:Mun0n,项目名称:MADBike,代码行数:24,代码来源:MapFragment.java

示例3: toString

import java.text.DecimalFormat; //导入方法依赖的package包/类
public String toString(Object obj){
  DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.ROOT);
  symbols.setDecimalSeparator('.');
  symbols.setGroupingSeparator(','); 
  
  DecimalFormat formatDecimal = new DecimalFormat("#0.00", symbols);
  formatDecimal.setRoundingMode(RoundingMode.HALF_UP);
  return formatDecimal.format((Double) obj);
}
 
开发者ID:pablopdomingos,项目名称:nfse,代码行数:10,代码来源:DoubleConversor.java

示例4: toString

import java.text.DecimalFormat; //导入方法依赖的package包/类
@Override
public String toString(Disk disk) {
    if (disk == null) {
        return "";
    }
    double bytesInGB = disk.getSize() / 1073741824.0;
    DecimalFormat df = new DecimalFormat("#.##"); 
    df.setRoundingMode(RoundingMode.CEILING);
    return disk.getName() + ": " + disk.model + " [" +  df.format(bytesInGB) + "GB]";

}
 
开发者ID:ciphertechsolutions,项目名称:IO,代码行数:12,代码来源:ProcessController.java

示例5: format

import java.text.DecimalFormat; //导入方法依赖的package包/类
public static String format(Number number, String prefix, String suffix, int numFractionDigits, boolean grouping){
	DecimalFormat df = new DecimalFormat();
	df.setMaximumFractionDigits(numFractionDigits);
	df.setMinimumFractionDigits(numFractionDigits);
	df.setRoundingMode(RoundingMode.HALF_UP);
	df.setGroupingUsed(grouping);
	df.setPositivePrefix(prefix);
	df.setNegativePrefix(prefix + "-");
	df.setPositiveSuffix(suffix);
	df.setNegativeSuffix(suffix);
	return df.format(number);
}
 
开发者ID:hotpads,项目名称:datarouter,代码行数:13,代码来源:NumberFormatter.java

示例6: getNumberFormat

import java.text.DecimalFormat; //导入方法依赖的package包/类
@Override
protected NumberFormat getNumberFormat(Locale locale) {
	DecimalFormat format = (DecimalFormat) NumberFormat.getCurrencyInstance(locale);
	format.setParseBigDecimal(true);
	format.setMaximumFractionDigits(this.fractionDigits);
	format.setMinimumFractionDigits(this.fractionDigits);
	if (this.roundingMode != null && roundingModeOnDecimalFormat) {
		format.setRoundingMode(this.roundingMode);
	}
	if (this.currency != null) {
		format.setCurrency(this.currency);
	}
	return format;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:15,代码来源:CurrencyFormatter.java

示例7: test

import java.text.DecimalFormat; //导入方法依赖的package包/类
public static <T extends TableBlock> String test(Collection<T> tableBlocks,int testCount)
{
	Random seed=new Random();
	String result="";
	int allCount=testCount;
	Map<T,Integer> map=new HashMap<T, Integer>();
	//统计元素出现次数
	for(int i=0;i<allCount;i++)
	{
		T item=randomBlock(tableBlocks, seed);
		if(map.containsKey(item))
		{
			int tmp=map.get(item);
			tmp++;
			map.put(item, tmp);
			
		}else
		{
			map.put(item, 1);
		}
	}
	//计算概率
	for(T key:map.keySet())
	{
		int count=map.get(key);
		DecimalFormat df = new DecimalFormat();  
	    df.setMaximumFractionDigits(2);// 设置精确2位小数   
	    df.setRoundingMode(RoundingMode.HALF_UP); //模式 例如四舍五入   
	    double p = (double)count/(double)allCount*100;//以100为计算概率200为实际总概率,则计算的概率会减半 
	    result="元素:"+key+"出现次数"+count+"/"+allCount+",出现概率:"+df.format(p)+"%";
	    System.out.println("元素:"+key+"出现次数"+count+"/"+allCount+",出现概率:"+df.format(p)+"%");
	}
	return result;
}
 
开发者ID:juebanlin,项目名称:util4j,代码行数:35,代码来源:TableLottery.java

示例8: formatPercentage

import java.text.DecimalFormat; //导入方法依赖的package包/类
public static String formatPercentage(double d) {

    // Defining that our percentage is precise down to 0.1%
    DecimalFormat df = new DecimalFormat("0.0");

    // Protecting this method against non-US locales that would not use '.' as decimal separation
    DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols();
    decimalFormatSymbols.setDecimalSeparator('.');
    df.setDecimalFormatSymbols(decimalFormatSymbols);

    // Making sure that we round the 0.1% properly out of the double value
    df.setRoundingMode(RoundingMode.HALF_UP);
    return df.format(d);
  }
 
开发者ID:AmadeusITGroup,项目名称:sonar-coverage-evolution,代码行数:15,代码来源:CoverageUtils.java

示例9: formatDays

import java.text.DecimalFormat; //导入方法依赖的package包/类
/**
 * Rounds <code>days</code> to <code>numDecimals</code> decimals and appends the pluralised "days" string.
 *
 * @param days The number of days to format.
 * @param context The application context.
 * @param quantityId The ID of the pluralised "days" string.
 * @param numDecimals The maximum number of decimals to use. If more would be needed, the days will be rounded.
 * @return The string representation.
 */
public static String formatDays(float days, Context context, int quantityId, int numDecimals) {
    StringBuilder builder = new StringBuilder(PATTERN_BASE + ".");
    for (int i = 0; i < numDecimals; ++i) {
        builder.append("#");
    }
    DecimalFormat decimalFormat = new DecimalFormat(builder.toString());
    int quantity = Math.round(days * 10.0f) == 10 ? 1 : 2;

    decimalFormat.setRoundingMode(RoundingMode.HALF_UP);
    return decimalFormat.format(days) + '\u00A0' + context.getResources().getQuantityText(quantityId, quantity);
}
 
开发者ID:mr-kojo,项目名称:Veggietizer,代码行数:21,代码来源:Formatter.java

示例10: formatDecimal2String

import java.text.DecimalFormat; //导入方法依赖的package包/类
/**
 * 格式化数字 double2string
 */
private CharSequence formatDecimal2String(double decimal) {
    String decimalScaleStr = "";
    String s = mDecimalFill ? "0" : "#";
    for (int i = 0; i < mDecimalScale; i++) {
        decimalScaleStr += s;
    }

    DecimalFormat formatter = (DecimalFormat) DecimalFormat.getInstance(Locale.getDefault());
    if (mShowCommas && !mShowSymbol) { // 显示数字分号 && 不显示数字符号
        formatter.applyPattern(",##0." + decimalScaleStr);
    } else if (mShowCommas) { // 显示数字分号 && 显示数字符号
        formatter.applyPattern(mSymbol + ",##0." + decimalScaleStr);
    } else if (mShowSymbol) { // 不显示数字分号 && 显示数字符号
        formatter.applyPattern(mSymbol + "#0." + decimalScaleStr);
    } else { // 不显示数字分号 && 不显示数字符号
        formatter.applyPattern("#0." + decimalScaleStr);
    }
    formatter.setRoundingMode(RoundingMode.DOWN);

    SpannableStringBuilder result = new SpannableStringBuilder(formatter.format(decimal));
    if (mShowSymbol) {
        if (mSymbolSize == 0) mSymbolSize = getTextSize();
        result.setSpan(new AbsoluteSizeSpan((int) mSymbolSize), 0, mSymbol.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    }

    return result;
}
 
开发者ID:ParfoisMeng,项目名称:DecimalTextView,代码行数:31,代码来源:ParfoisDecimalEditText.java

示例11: arredondarDuasCasas

import java.text.DecimalFormat; //导入方法依赖的package包/类
public static Double arredondarDuasCasas(Double valor){
  DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.US);
  DecimalFormat df = new DecimalFormat("###.##", symbols);
  df.setRoundingMode(RoundingMode.HALF_EVEN);
  return Double.valueOf(df.format(valor));
}
 
开发者ID:pablopdomingos,项目名称:nfse,代码行数:7,代码来源:DoubleUtil.java

示例12: doubleNumberFormat

import java.text.DecimalFormat; //导入方法依赖的package包/类
public String doubleNumberFormat(double number) {
    DecimalFormat format = new DecimalFormat("###########0.00");
    format.setRoundingMode(RoundingMode.FLOOR);
    return format.format(number);
}
 
开发者ID:YunzhanghuOpen,项目名称:redpacketui-open,代码行数:6,代码来源:RPBaseDialogFragment.java

示例13: updateScreenState

import java.text.DecimalFormat; //导入方法依赖的package包/类
/**
 * update the the lower gui section with the Values from an AnswerScreenState
 * @param state
 * history: if true, do not update the title
 */
public void updateScreenState(final AnswerScreenState state, final boolean history){



    DecimalFormat df = new DecimalFormat("#.###");
    df.setRoundingMode(RoundingMode.CEILING);
    final String ampFactor = df.format(state.ampFactor);

    Runnable guiUpdate = new Runnable() {
        @Override
        public void run() {
            if (!history){
                setTitle("");
            }

            ((TextView) findViewById(R.id.txtStatusText)).setText(state.status);
            ((TextView) findViewById(R.id.txtServerIP)).setText(state.server);
            ((TextView) findViewById(R.id.txtQbytes)).setText(""+state.qsize);
            ((TextView) findViewById(R.id.txtAbytes)).setText(""+state.asize);
            ((TextView) findViewById(R.id.txtAmpfactor)).setText(ampFactor);
            ((EditText) findViewById(R.id.txtResult)).setText(state.answerText);
            if (state.rcode>-1) {
                ((TextView) findViewById(R.id.txtRcode)).setText(Rcode.string(state.rcode));
            } else {
                ((TextView) findViewById(R.id.txtRcode)).setText("");

            }


            ((CheckBox) findViewById(R.id.cbaAA)).setChecked(  state.flag_AA);
            ((CheckBox) findViewById(R.id.cbaTC)).setChecked(  state.flag_TC);
            ((CheckBox) findViewById(R.id.cbaRD)).setChecked(  state.flag_RD);
            ((CheckBox) findViewById(R.id.cbaRA)).setChecked(  state.flag_RA);
            ((CheckBox) findViewById(R.id.cbaAD)).setChecked(  state.flag_AD);
            ((CheckBox) findViewById(R.id.cbaCD)).setChecked(  state.flag_CD);


        }
    };

    runOnUiThread(guiUpdate);
}
 
开发者ID:gryphius,项目名称:androdns,代码行数:48,代码来源:DNSFormActivity.java

示例14: formatShow

import java.text.DecimalFormat; //导入方法依赖的package包/类
private static String formatShow(BigDecimal value) {
  DecimalFormat percentFormat = new DecimalFormat(MASK);
  percentFormat.setDecimalSeparatorAlwaysShown(false);
  percentFormat.setRoundingMode(RoundingMode.DOWN);
  return percentFormat.format(value).replace(',', '.');
}
 
开发者ID:AtlantPlatform,项目名称:atlant-android,代码行数:7,代码来源:DigitsUtils.java

示例15: roundValue

import java.text.DecimalFormat; //导入方法依赖的package包/类
/**
 * Rounds a value by using the specified scale with half up rounding and
 * without grouping. Even if the last part of the decimal value is 0 in
 * specified fraction digits, always all decimal places are filled with 0.
 * (e.g. value 1.2, 5 fraction digits, en locale => '1.20000' will be
 * returned)
 * 
 * @param value
 *            Value to be formatted.
 * @param locale
 *            Current user's locale for formatting.
 * @param fractionDigits
 *            Number of decimal places.
 * @return
 */
public static String roundValue(BigDecimal value, Locale locale,
        int fractionDigits) {
    DecimalFormat df = new DecimalFormat();
    df.setDecimalFormatSymbols(new DecimalFormatSymbols(locale));
    df.setGroupingUsed(false);
    df.setMaximumFractionDigits(fractionDigits);
    df.setMinimumFractionDigits(fractionDigits);
    df.setRoundingMode(RoundingMode.HALF_UP);
    return df.format(value);
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:26,代码来源:ValueRounder.java


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