本文整理汇总了Java中java.text.NumberFormat.setMinimumFractionDigits方法的典型用法代码示例。如果您正苦于以下问题:Java NumberFormat.setMinimumFractionDigits方法的具体用法?Java NumberFormat.setMinimumFractionDigits怎么用?Java NumberFormat.setMinimumFractionDigits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.text.NumberFormat
的用法示例。
在下文中一共展示了NumberFormat.setMinimumFractionDigits方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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());
}
示例2: setZoomHistoryPast
import java.text.NumberFormat; //导入方法依赖的package包/类
public void setZoomHistoryPast(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);
// set zoom
if (getZoomHistoryPast().contentEquals("0")) {
pastZoom = "past, " + p2.getX() + ", " + p2.getY() + ", " + zoom;
zoomActionTrack.selectAll();
zoomActionTrack.replaceSelection(pastZoom);
//System.out.println("jtext " + zoomActionTrack.getText());
}
}
示例3: percent2
import java.text.NumberFormat; //导入方法依赖的package包/类
public static String percent2(double p1, double p2) {
String str;
double p3 = p1 / p2;
NumberFormat nf = NumberFormat.getPercentInstance();
nf.setMinimumFractionDigits(0);
str = nf.format(p3);
return str;
}
示例4: 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;
}
示例5: getPercent
import java.text.NumberFormat; //导入方法依赖的package包/类
/**
* 获得下载的百分比, 保留两位小数
*
* @return example: 5.25%
*/
public String getPercent() {
String percent;
Double result;
if (totalSize == 0L) {
result = 0.0;
} else {
result = downloadSize * 1.0 / totalSize;
}
NumberFormat nf = NumberFormat.getPercentInstance();
nf.setMinimumFractionDigits(2);//控制保留小数点后几位,2:表示保留2位小数点
percent = nf.format(result);
return percent;
}
示例6: 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);
}
示例7: formatNumber
import java.text.NumberFormat; //导入方法依赖的package包/类
public static String formatNumber(double number, int decimal) {
if (number >= 0) {
NumberFormat n = NumberFormat.getNumberInstance();
if (decimal > 0) {
n.setMinimumFractionDigits(decimal);
n.setMaximumFractionDigits(decimal);
}
return n.format(number);
} else {
return "";
}
}
示例8: getKDR
import java.text.NumberFormat; //导入方法依赖的package包/类
public String getKDR() {
NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(2);
nf.setMinimumFractionDigits(2);
if (getDeaths() == 0) return nf.format((double) getKills());
return nf.format((double) getKills()/getDeaths());
}
示例9: getWLR
import java.text.NumberFormat; //导入方法依赖的package包/类
public String getWLR() {
NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(2);
nf.setMinimumFractionDigits(2);
if (getLosses() == 0) return nf.format((double) getWins());
return nf.format((double) getWins()/getLosses());
}
示例10: ToString
import java.text.NumberFormat; //导入方法依赖的package包/类
public static String ToString(double d, Locale loc) {
NumberFormat nf = NumberFormat.getInstance(loc);
nf.setGroupingUsed(false);
if (loc == LocaleSupport.INVARIANT)
{
nf.setMinimumFractionDigits(1);
nf.setMaximumFractionDigits(7);
}
return nf.format(d);
}
示例11: percent
import java.text.NumberFormat; //导入方法依赖的package包/类
public static String percent(double p1, double p2) {
String str;
double p3 = p1 / p2;
NumberFormat nf = NumberFormat.getPercentInstance();
nf.setMinimumFractionDigits(2);
str = nf.format(p3);
return str;
}
示例12: getMeasuresRow
import java.text.NumberFormat; //导入方法依赖的package包/类
public List<String> getMeasuresRow(Object[] measures, String title) {
NumberFormat f = NumberFormat.getInstance(Locale.ENGLISH);
f.setMaximumFractionDigits(4);
f.setMinimumFractionDigits(4);
f.setRoundingMode(RoundingMode.HALF_UP);
List<String> row = new ArrayList<String>();
row.add(title);
row.add(Integer.toString(getCorrectMatches()));
row.add(Integer.toString(getMissing()));
row.add(Integer.toString(getSpurious()));
row.add(Integer.toString(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(getPrecisionStrict()));
row.add(f.format(getRecallStrict()));
row.add(f.format(getFMeasureStrict(beta)));
} else if (measure.endsWith("lenient")) {
row.add(f.format(getPrecisionLenient()));
row.add(f.format(getRecallLenient()));
row.add(f.format(getFMeasureLenient(beta)));
} else if (measure.endsWith("average")) {
row.add(f.format(getPrecisionAverage()));
row.add(f.format(getRecallAverage()));
row.add(f.format(getFMeasureAverage(beta)));
}
}
return row;
}
示例13: formatLocalisedNumberForceDecimalPlaces
import java.text.NumberFormat; //导入方法依赖的package包/类
/**
* Format a given float or double to the I18N format specified by the locale, with a fixed number of decimal places.
* If numFractionDigits is 2: 4.051 -> 4.05, 4 -> 4.00
*
* @param mark
* @param locale
* @param numFractionDigits
* @return
*/
public static String formatLocalisedNumberForceDecimalPlaces(Number number, Locale locale, int numFractionDigits) {
NumberFormat format = null;
if (locale == null) {
format = NumberFormat.getInstance(NumberUtil.getServerLocale());
} else {
format = NumberFormat.getInstance(locale);
}
format.setMinimumFractionDigits(numFractionDigits);
return format.format(number);
}
示例14: populateAdapter
import java.text.NumberFormat; //导入方法依赖的package包/类
protected void populateAdapter( RecyclerViewAdapter adapter, Bundle bundle, Scan scan ) {
if( scan != null ){
JsonMapper result = JsonMapper.from( scan.getResult() );
this.tvReciboTipo.setText( R.string.recibo_inscricao );
NumberFormat numberFormat = NumberFormat.getNumberInstance();
numberFormat.setMinimumIntegerDigits( 1 );
numberFormat.setMinimumFractionDigits( 0 );
numberFormat.setMaximumFractionDigits( 4 );
result.enter( "body", "nota" );
// Lancador da nota A
ItemRow.DataSet lancadorA = ItemRow.newDataSet(getString(R.string.lancador_a), result.string("colaborador_lancamentoa", "colaborador_nomecompleto") )
.setImageIcon( R.drawable.ic_person_teal_500_24dp )
;
String notaValue = ( result.doubler("nota_exameacessoa" ) != null )? numberFormat.format( result.doubler("nota_exameacessoa" ) ) : "";
ItemRow.DataSet notaA = ItemRow.newDataSet(getString(R.string.value_a), notaValue )
;
ItemRow.DataSet dataA = ItemRow.newDataSet(getString(R.string.data_a), result.string("nota_datalancamentotextA") )
.setSepartator( true )
;
// Lancador da nota A
ItemRow.DataSet lancadorB = ItemRow.newDataSet(getString(R.string.lancador_b), result.string( "colaborador_lancamentob", "colaborador_nomecompleto" ) )
.setImageIcon( R.drawable.ic_person_teal_500_24dp )
;
notaValue = ( result.doubler("nota_exameacessob" ) != null )? numberFormat.format( result.doubler("nota_exameacessob" ) ) : "";
ItemRow.DataSet notaB = ItemRow.newDataSet(getString(R.string.value_b), notaValue )
;
ItemRow.DataSet dataB = ItemRow.newDataSet(getString(R.string.data_b), result.string("nota_datalancamentotextB") )
;
this.adapter.addItem( lancadorA );
this.adapter.addItem( notaA );
this.adapter.addItem( dataA );
this.adapter.addItem( lancadorB );
this.adapter.addItem( notaB );
this.adapter.addItem( dataB );
}
}
示例15: test
import java.text.NumberFormat; //导入方法依赖的package包/类
public static List<Result> test(
final Random random,
final List<String> args,
final PrintStream out
)
throws IOException, InterruptedException
{
final List<String> dieharderArgs = new ArrayList<>();
dieharderArgs.add("dieharder");
dieharderArgs.addAll(args);
dieharderArgs.add("-g");
dieharderArgs.add("200");
printv(out);
final long start = System.currentTimeMillis();
final ProcessBuilder builder = new ProcessBuilder(dieharderArgs);
final Process dieharder = builder.start();
final Randomizer randomizer = new Randomizer(
random,
dieharder.getOutputStream()
);
final Thread randomizerThread = new Thread(randomizer);
randomizerThread.start();
// The dieharder console output.
final BufferedReader stdout = new BufferedReader (
new InputStreamReader(dieharder.getInputStream())
);
final List<Result> results = new ArrayList<>();
for (String l = stdout.readLine(); l != null; l = stdout.readLine()) {
Result.parse(l).ifPresent(results::add);
System.out.println(l);
}
dieharder.waitFor();
randomizerThread.interrupt();
final long millis = System.currentTimeMillis() - start;
final long sec = millis/1000;
final double megaBytes = randomizer.getCount()/(1024.0*1024.0);
// Calculate statistics.
final Map<Assessment, Long> grouped = results.stream()
.collect(groupingBy(r -> r.assessment, counting()));
final long passed = grouped.getOrDefault(Assessment.PASSED, 0L);
final long weak = grouped.getOrDefault(Assessment.WEAK, 0L);
final long failed = grouped.getOrDefault(Assessment.FAILED, 0L);
final NumberFormat formatter = NumberFormat.getIntegerInstance();
formatter.setMinimumFractionDigits(3);
formatter.setMaximumFractionDigits(3);
println(out, "#=============================================================================#");
println(out,
"# %-76s#",
format("Summary: PASSED=%d, WEAK=%d, FAILED=%d", passed, weak, failed)
);
println(out,
"# %-76s#",
format(" %s MB of random data created with %s MB/sec",
formatter.format(megaBytes),
formatter.format(megaBytes/(millis/1000.0))
)
);
println(out, "#=============================================================================#");
printt(out, "Runtime: %d:%02d:%02d", sec/3600, (sec%3600)/60, sec%60);
return results;
}