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


Java DecimalFormat.setMinimumFractionDigits方法代码示例

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


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

示例1: adjustForCurrencyDefaultFractionDigits

import java.text.DecimalFormat; //导入方法依赖的package包/类
/**
 * Adjusts the minimum and maximum fraction digits to values that
 * are reasonable for the currency's default fraction digits.
 */
private static void adjustForCurrencyDefaultFractionDigits(
        DecimalFormat format, DecimalFormatSymbols symbols) {
    Currency currency = symbols.getCurrency();
    if (currency == null) {
        try {
            currency = Currency.getInstance(symbols.getInternationalCurrencySymbol());
        } catch (IllegalArgumentException e) {
        }
    }
    if (currency != null) {
        int digits = currency.getDefaultFractionDigits();
        if (digits != -1) {
            int oldMinDigits = format.getMinimumFractionDigits();
            // Common patterns are "#.##", "#.00", "#".
            // Try to adjust all of them in a reasonable way.
            if (oldMinDigits == format.getMaximumFractionDigits()) {
                format.setMinimumFractionDigits(digits);
                format.setMaximumFractionDigits(digits);
            } else {
                format.setMinimumFractionDigits(Math.min(digits, oldMinDigits));
                format.setMaximumFractionDigits(digits);
            }
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:30,代码来源:NumberFormatProviderImpl.java

示例2: test1

import java.text.DecimalFormat; //导入方法依赖的package包/类
public static void test1(DecimalFormat df) {
	//默认显示3位小数
	double d = 1.5555555;
	System.out.println(df.format(d));//1.556
	//设置小数点后最大位数为5
	df.setMaximumFractionDigits(5);
	df.setMinimumIntegerDigits(15);
	System.out.println(df.format(d));//1.55556
	df.setMaximumFractionDigits(2);
	System.out.println(df.format(d));//1.56
	//设置小数点后最小位数,不够的时候补0
	df.setMinimumFractionDigits(10);
	System.out.println(df.format(d));//1.5555555500
	//设置整数部分最小长度为3,不够的时候补0
	df.setMinimumIntegerDigits(3);
	System.out.println(df.format(d));
	//设置整数部分的最大值为2,当超过的时候会从个位数开始取相应的位数
	df.setMaximumIntegerDigits(2);
	System.out.println(df.format(d));
}
 
开发者ID:juebanlin,项目名称:util4j,代码行数:21,代码来源:TestDecimalFormat.java

示例3: formatPercent

import java.text.DecimalFormat; //导入方法依赖的package包/类
public static String formatPercent(double done, int digits) {
  DecimalFormat percentFormat = new DecimalFormat("0.00%");
  double scale = Math.pow(10.0D, digits + 2);
  double rounded = Math.floor(done * scale);
  percentFormat.setDecimalSeparatorAlwaysShown(false);
  percentFormat.setMinimumFractionDigits(digits);
  percentFormat.setMaximumFractionDigits(digits);
  return percentFormat.format(rounded / scale);
}
 
开发者ID:Tencent,项目名称:angel,代码行数:10,代码来源:StringUtils.java

示例4: print

import java.text.DecimalFormat; //导入方法依赖的package包/类
/** Print the matrix to the output stream.   Line the elements up in
  * columns with a Fortran-like 'Fw.d' style format.
@param output Output stream.
@param w      Column width.
@param d      Number of digits after the decimal.
*/

public void print (PrintWriter output, int w, int d) {
   DecimalFormat format = new DecimalFormat();
   format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US));
   format.setMinimumIntegerDigits(1);
   format.setMaximumFractionDigits(d);
   format.setMinimumFractionDigits(d);
   format.setGroupingUsed(false);
   print(output,format,w+2);
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:17,代码来源:Matrix.java

示例5: sendOrderSummary

import java.text.DecimalFormat; //导入方法依赖的package包/类
@Transactional
public void sendOrderSummary(LocalDate date) {

    DailyMenu dailyMenu = dailyMenuRep.findByDate(date);
    if (dailyMenu != null) {

        DateTimeFormatter fmt = DateTimeFormat.forPattern("dd/MM/yyyy");
        DateTimeFormatter fmtFull = DateTimeFormat.forPattern("EEEE dd MMMM yyyy");

        String formattedDate = date.toString(fmt);
        String titleDate = date.toString(fmtFull);
        DecimalFormat df = new DecimalFormat();
        df.setMaximumFractionDigits(2);
        df.setMinimumFractionDigits(2);

        String currency = settingsRep.findById(1).getCurrency();

        //Build data
        HashMap<String, HashMap<Food, Integer>> orderByFoodType = getFoodByType(getOrderItems(dailyMenu));

        // create hashmap for the placeholders of the template
        Map<String, Object> model = new HashMap<>();
        model.put("date", titleDate);
        model.put("orderItemsByMain", orderByFoodType.get("MAIN"));
        model.put("orderItemsBySalad", orderByFoodType.get("SALAD"));
        model.put("orderItemsByDrink", orderByFoodType.get("DRINK"));
        model.put("currency", currency);

        List<DailyOrder> dailyOrders = dailyMenu.getDailyOrders();
        model.put("dailyOrders", dailyOrders);

        String emails = settingsRep.findById(1).getReportEmail();
        if (emails != null && !emails.isEmpty()) {
            ArrayList<String> emailsTo = new ArrayList<>(Arrays.asList(emails.split(";")));
            for (String emailTo : emailsTo) {
                sendHtmlTemplateEmail(emailTo, "[Yum] Order summary for " + formattedDate, model, "order-summary.ftlh");
            }
        }
    }
}
 
开发者ID:jrtechnologies,项目名称:yum,代码行数:41,代码来源:EmailService.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: setFormatterDigits

import java.text.DecimalFormat; //导入方法依赖的package包/类
/** Sets the number of fractional decimal places to be displayed on the given
 *  NumberFormat object to the value of the given integer.
 *  @return The minimum and maximum fractional places settings that the
 *          formatter had before this change, as an ImmutableList. */
private static ImmutableList<Integer> setFormatterDigits(DecimalFormat formatter, int min, int max) {
    ImmutableList<Integer> ante = ImmutableList.of(
        formatter.getMinimumFractionDigits(),
        formatter.getMaximumFractionDigits()
    );
    formatter.setMinimumFractionDigits(min);
    formatter.setMaximumFractionDigits(max);
    return ante;
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:14,代码来源:BtcFormat.java

示例8: testToString

import java.text.DecimalFormat; //导入方法依赖的package包/类
/**
 * Tests the functionality of the toString-method.
 */
@Test
public final void testToString() {
    ItemSet<NamedItem> body1 = new ItemSet<>();
    body1.add(new NamedItem("a"));
    body1.setSupport(0.5);
    ItemSet<NamedItem> body2 = new ItemSet<>();
    body2.add(new NamedItem("b"));
    body2.setSupport(0.8);
    AssociationRule<NamedItem> associationRule1 = new AssociationRule<>(body1, new ItemSet<>(),
            0.5);
    AssociationRule<NamedItem> associationRule2 = new AssociationRule<>(body2, new ItemSet<>(),
            0.7);
    RuleSet<NamedItem> ruleSet = new RuleSet<>(Sorting.forAssociationRules());
    ruleSet.add(associationRule1);
    ruleSet.add(associationRule2);
    DecimalFormat decimalFormat = new DecimalFormat();
    decimalFormat.setMinimumFractionDigits(1);
    decimalFormat.setMaximumFractionDigits(2);
    assertEquals("[" + associationRule1.toString() + " (support = " +
                    decimalFormat.format(new Support().evaluate(associationRule1)) + ", confidence = " +
                    decimalFormat.format(new Confidence().evaluate(associationRule1)) + ", lift = " +
                    decimalFormat.format(new Lift().evaluate(associationRule1)) + ", leverage = " +
                    decimalFormat.format(new Leverage().evaluate(associationRule1)) + "),\n"
                    + associationRule2.toString() + " (support = " +
                    decimalFormat.format(new Support().evaluate(associationRule2)) + ", confidence = " +
                    decimalFormat.format(new Confidence().evaluate(associationRule2)) + ", lift = " +
                    decimalFormat.format(new Lift().evaluate(associationRule2)) + ", leverage = " +
                    decimalFormat.format(new Leverage().evaluate(associationRule2)) + ")]",
            ruleSet.toString());
}
 
开发者ID:michael-rapp,项目名称:Apriori,代码行数:34,代码来源:RuleSetTest.java

示例9: print

import java.text.DecimalFormat; //导入方法依赖的package包/类
/**
 * Print the matrix to the output stream.   Line the elements up in
 * columns with a Fortran-like 'Fw.d' style format.
 *
 * @param output Output stream.
 * @param w      Column width.
 * @param d      Number of digits after the decimal.
 */

public void print(PrintWriter output, int w, int d)
{
    DecimalFormat format = new DecimalFormat();
    format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US));
    format.setMinimumIntegerDigits(1);
    format.setMaximumFractionDigits(d);
    format.setMinimumFractionDigits(d);
    format.setGroupingUsed(false);
    print(output, format, w + 2);
}
 
开发者ID:priester,项目名称:hanlpStudy,代码行数:20,代码来源:Matrix.java

示例10: getFuelVolume

import java.text.DecimalFormat; //导入方法依赖的package包/类
public static String getFuelVolume(double value) {
    DecimalFormat bddf = new DecimalFormat();
    bddf.setGroupingUsed(false);
    bddf.setMaximumFractionDigits(2);
    bddf.setMinimumFractionDigits(0);

    return bddf.format(value);
}
 
开发者ID:piskula,项目名称:FuelUp,代码行数:9,代码来源:VolumeUtil.java

示例11: getFormatterForConsumption

import java.text.DecimalFormat; //导入方法依赖的package包/类
public static DecimalFormat getFormatterForConsumption(String consumptionUnit) {
    DecimalFormat format = new DecimalFormat();

    if (MainActivity.getInstance().getString(R.string.units_mpg).equals(consumptionUnit)) {
        format.setMaximumFractionDigits(1);
        format.setMinimumFractionDigits(1);
    } else {
        format.setMaximumFractionDigits(2);
        format.setMinimumFractionDigits(2);
    }

    return format;
}
 
开发者ID:piskula,项目名称:FuelUp,代码行数:14,代码来源:VolumeUtil.java

示例12: getPriceFormatted

import java.text.DecimalFormat; //导入方法依赖的package包/类
private static String getPriceFormatted(double value, int coefficient, boolean isBefore, int fractionDigits, String symbol) {
    DecimalFormat bddf = new DecimalFormat();
    bddf.setMaximumFractionDigits(fractionDigits);
    bddf.setMinimumFractionDigits(fractionDigits);
    String price = bddf.format(value * coefficient);

    if (isBefore) {
        return symbol + " " + price;
    } else {
        return price + " " + symbol;
    }
}
 
开发者ID:piskula,项目名称:FuelUp,代码行数:13,代码来源:CurrencyUtil.java

示例13: ListFillUpsAdapter

import java.text.DecimalFormat; //导入方法依赖的package包/类
public ListFillUpsAdapter(Callback callback, Vehicle vehicle) {
    super();

    this.mVehicle = vehicle;
    this.mCallback = callback;

    int consumptionFractionDigits = mVehicle.getDistanceUnit() == DistanceUnit.mi ? 1 : 2;
    consumptionFormat = new DecimalFormat();
    consumptionFormat.setGroupingUsed(false);
    consumptionFormat.setMinimumFractionDigits(consumptionFractionDigits);
    consumptionFormat.setMaximumFractionDigits(consumptionFractionDigits);
}
 
开发者ID:piskula,项目名称:FuelUp,代码行数:13,代码来源:ListFillUpsAdapter.java

示例14: getValue

import java.text.DecimalFormat; //导入方法依赖的package包/类
@Override
protected Object getValue(boolean dummy) {
	try{		
		
		DecimalFormat df = new DecimalFormat();
		df.setMaximumFractionDigits(2);
		df.setMinimumFractionDigits(2);
		
		return df.format(BED.gameKdr) + " (" + (BED.gameKdr - BED.apiKdr > 0 ? "+" + df.format(BED.gameKdr - BED.apiKdr) : df.format(BED.gameKdr - BED.apiKdr)) + ")";
	}catch(Exception e){
			e.printStackTrace();
			return "Server error";
	}
}
 
开发者ID:RoccoDev,项目名称:5zig-TIMV-Plugin,代码行数:15,代码来源:KDRChangeItem.java

示例15: toString

import java.text.DecimalFormat; //导入方法依赖的package包/类
@Override
public final String toString() {
    StringBuilder stringBuilder = new StringBuilder();
    DecimalFormat decimalFormat = new DecimalFormat();
    decimalFormat.setMinimumFractionDigits(1);
    decimalFormat.setMaximumFractionDigits(2);
    Iterator<AssociationRule<ItemType>> iterator = iterator();
    stringBuilder.append("[");

    while (iterator.hasNext()) {
        AssociationRule<ItemType> rule = iterator.next();
        stringBuilder.append(rule.toString());
        stringBuilder.append(" (support = ");
        stringBuilder.append(decimalFormat.format(new Support().evaluate(rule)));
        stringBuilder.append(", confidence = ");
        stringBuilder.append(decimalFormat.format(new Confidence().evaluate(rule)));
        stringBuilder.append(", lift = ");
        stringBuilder.append(decimalFormat.format(new Lift().evaluate(rule)));
        stringBuilder.append(", leverage = ");
        stringBuilder.append(decimalFormat.format(new Leverage().evaluate(rule)));
        stringBuilder.append(")");

        if (iterator.hasNext()) {
            stringBuilder.append(",\n");
        }
    }

    stringBuilder.append("]");
    return stringBuilder.toString();
}
 
开发者ID:michael-rapp,项目名称:Apriori,代码行数:31,代码来源:RuleSet.java


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