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


Java DecimalFormat.format方法代码示例

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


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

示例1: getExpPerHour

import java.text.DecimalFormat; //导入方法依赖的package包/类
/**
 * Returns the experience per hour.
 * 
 * @return The experience per hour as a string.
 */
public String getExpPerHour(){
	if(characterSpecificExpPerHourReferenceLow == 0 || characterSpecificExpPerHourReferenceHigh == 0){
		return "next update";
	}
	else{
		long exp = characterSpecificExpPerHourReferenceHigh-characterSpecificExpPerHourReferenceLow;
		int time = (characterSpecificExpPerHourTimestampHigh-characterSpecificExpPerHourTimestampLow)/1000;
		int expPerHour = (int) (exp/time)*60*60;			
		double tmp;
		DecimalFormat decimalFormat = new DecimalFormat("##0.0");
		
		if(expPerHour < 999){
			tmp = (double) expPerHour;
			return  Integer.toString(expPerHour);
		}
		else if(expPerHour < 999999){
			tmp = (double) expPerHour/1000;
			return decimalFormat.format(tmp) + "K";
		}
		else{
			tmp = (double) expPerHour/1000000;
			return decimalFormat.format(tmp) + "M";
		}
	}
}
 
开发者ID:jkjoschua,项目名称:poe-ladder-tracker-java,代码行数:31,代码来源:LadderCSV.java

示例2: setProgeress

import java.text.DecimalFormat; //导入方法依赖的package包/类
/** set progress value at progress bar when send file */
public void setProgeress(int index, double value, long onGoing, long fileLength, boolean isDownloading) {
	double onGoingMB = ((onGoing / 1024.0) / 1024.0);
	double fileLengthMB = ((fileLength / 1024.0) / 1024.0);

	DecimalFormat dec = new DecimalFormat("0.0");

	String progress = (int) value + "% (" + dec.format(onGoingMB) + " / " + dec.format(fileLengthMB) + " MB)";

	Platform.runLater(() -> {
		try {
			if(!isDownloading)
				textArray[index].setText("Uploading " + progress);
			else
				textArray[index].setText("Downloading " + progress);

			progressBarArray[index].setProgress(value*0.01);
		} catch (ArrayIndexOutOfBoundsException e) {
			System.out.println("index exception");
		}
	});
}
 
开发者ID:Team-Sprout,项目名称:Clipcon-Client,代码行数:23,代码来源:ProgressBarScene.java

示例3: printMatrix

import java.text.DecimalFormat; //导入方法依赖的package包/类
/**
 * 用于把矩阵输出到文件中
 *
 * @param matrix
 * @param outputPath
 */
public static void printMatrix(Matrix matrix, String outputPath) {
    long[] size = matrix.getSize();
    long m = size[0]; long n = size[1];
    String cont = "";
    DecimalFormat df = new DecimalFormat("#0.000000");
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < n; j++) {
            cont = cont + df.format(matrix.getAsDouble(i,j)) + " ";
        }
        cont = cont + "\n";
    }
    try {
        FileUtils.write(new File(outputPath), cont, "utf-8");
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:guozhaotong,项目名称:FacetExtract,代码行数:24,代码来源:AAppearedFacet.java

示例4: printMem

import java.text.DecimalFormat; //导入方法依赖的package包/类
public static String printMem(long bytes) {
    double dbytes = (double) bytes;
    DecimalFormat df = new DecimalFormat("#.##");

    if (dbytes < 1024) {
        return df.format(bytes);
    } else if (dbytes < 1024 * 1024) {
        return df.format(dbytes / 1024);
    } else if (dbytes < 1024 * 1024 * 1024) {
        return df.format(dbytes / 1024 / 1024) + "M";
    } else if (dbytes < 1024 * 1024 * 1024 * 1024L) {
        return df.format(dbytes / 1024 / 1024 / 1024) + "G";
    } else {
        return "Too big to show you";
    }
}
 
开发者ID:weiboad,项目名称:fiery,代码行数:17,代码来源:Toolbox.java

示例5: formatNumber

import java.text.DecimalFormat; //导入方法依赖的package包/类
public static String formatNumber(double number, String pattern,
                                  DecimalFormat formatter) {
    // bugzilla fix 12813
    if (formatter == null) {
        formatter = defaultFormatter;
    }
    try {
        StringBuffer result = threadLocalStringBuffer.get();
    result.setLength(0);
        if (pattern != defaultPattern) {
            formatter.applyLocalizedPattern(pattern);
        }
    formatter.format(number, result, _fieldPosition);
        return result.toString();
    }
    catch (IllegalArgumentException e) {
        runTimeError(FORMAT_NUMBER_ERR, Double.toString(number), pattern);
        return(EMPTYSTRING);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:BasisLibrary.java

示例6: displayTable

import java.text.DecimalFormat; //导入方法依赖的package包/类
@Override
  protected void displayTable(HttpServletResponse response) throws SQLException, IOException {
  	response.setIntHeader("Refresh", 5);
  	
  	// Append table that lists all persons
      List<SM> resultList = smDAO.selectAllEntries();
      response.getWriter().println(
              "<p><center><table width=70% border=\"1\"><tr><th colspan=\"1\"></th>" + "<th colspan=\"3\">" + (resultList.isEmpty() ? "" : resultList.size() + " ")
                      + "Employees in the EPM-BPC team</th>"
                      + "<th colspan=\"3\">" + "Smart Sorted</th></tr>");
      if (resultList.isEmpty()) {
          response.getWriter().println("<tr><td colspan=\"4\">Database is empty</td></tr>");
      } else {
          response.getWriter().println("<tr><th>#</th><th>Name</th><th>Assign</th><th>Remove</th><th>Amount</th><th>Total</th><th>AVG Q-DAY</th></tr>");
      }
      IXSSEncoder xssEncoder = XSSEncoder.getInstance();
      int index = 1;
      Collections.sort(resultList); 
   
      // Add [EPM_QM_ASSIGNED] button
  	response.getWriter().println("<p><center> Click here &#8594;  <input type=\"submit\" onclick=\"return window.prompt('Copy to clipboard: ','[EPM_QM_ASSIGNED]')\" value=\"[EPM_QM_ASSIGNED]\"></center></p>");
      
      int smIncidents = 0;
      for (SM sm : resultList) {        	
      	// Graham = 4, Stefan = 12
      	if (sm.getId() == 4 || sm.getId()==12) {
      		// Calculate incident number
      		smIncidents += sm.getSm();
      		
      		// Get score
       	String score = "0";
       	
      		DecimalFormat df = new DecimalFormat("#.###");
      		score = df.format(((double)sm.getSum()) / QueueDays.hash.get(sm.getName()));
      	
       	
       	String pop = sm.getName() + " has been +1, please go for assign.";
       	String link = "<td><center><form action=\"" + LINKNAME + "?Id="+ sm.getId() + "&operation=add\" method=\"post\">" + "<input type=\"submit\" onclick=\"return window.prompt('" + pop + " Copy to clipboard: Ctrl+C, Enter','" + sm.getiNumber() + "')\" value=\"Add\" />" + "</form></center></td>";
       	
       	if (sm.getSum() < FIXEDVALUE) {
       		response.getWriter().println("<tr><td height=\"30\"><center>" + (index++) + "</center></td>");
        	if (index == 2) {
        		response.getWriter().println("<td height=\"30\"><center><mark><b>" + xssEncoder.encodeHTML(sm.getName()+" ("+sm.getiNumber()+")") + "</b></mark></center></td>");
        	} else {
        		response.getWriter().println("<td height=\"30\"><center>" + xssEncoder.encodeHTML(sm.getName()+" ("+sm.getiNumber()+")") + "</center></td>");
        	}
       		response.getWriter().println(link); 
       		response.getWriter().println("<td><center><form action=\"" + LINKNAME + "?Id="+ sm.getId() + "&operation=decrease\" method=\"post\">" + "<input type=\"submit\" value=\"Delete\" />" + "</form></center></td>"); 
        	response.getWriter().println("<td height=\"30\"><center>" + sm.getSm() + "</center></td>");
			response.getWriter().println("<td height=\"30\"><center>" + sm.getSum() + "</center></td>" + "<td height=\"30\"><center>" + score + "</center></td>");
       	} else {
        	response.getWriter().println("<tr><td height=\"30\"><center>" + (index++) + "</center></td>");
        	response.getWriter().println("<td height=\"30\"><center>" + xssEncoder.encodeHTML(sm.getName() + ": UNAVAILABLE") + "</center></td>");
        	response.getWriter().println("<td><center>"+ xssEncoder.encodeHTML("N/A") + "</center></td>"); 
        	response.getWriter().println("<td><center>"+ xssEncoder.encodeHTML("N/A") + "</center></td>"); 
        	response.getWriter().println("<td height=\"30\"><center>" + sm.getSm() + "</center></td>");
			response.getWriter().println("<td height=\"30\"><center>" + (sm.getSum()-FIXEDVALUE) + "</center></td>");
       	}
       	
		response.getWriter().println("</tr>");
      	}
      }
      response.getWriter().println("</table></center></p>");

response.getWriter().println("<p><center>SM has <mark>" + smIncidents + "</mark> incidents" + "</center></p>");
response.getWriter().println("</body>");
      	     
// Home button
response.getWriter().println("<p><center><form action=\"" + "nw" + "\" method=\"get\">" + "<input type=\"submit\" value=\"Return to Home\" />" + "</form></center></p>");
      	
      
  }
 
开发者ID:qianyilun,项目名称:Queue-Manager-Cloud-Dispatcher,代码行数:73,代码来源:PersistenceWithSM.java

示例7: toString

import java.text.DecimalFormat; //导入方法依赖的package包/类
@Override
public String toString() {
    DecimalFormat format = new DecimalFormat();
    format.setMinimumFractionDigits(precision);
    format.setMaximumFractionDigits(precision);
    DecimalFormatSymbols dfs = format.getDecimalFormatSymbols();
    dfs.setDecimalSeparator(DECIMAL_SEPARATOR);
    format.setDecimalFormatSymbols(dfs);
    format.setGroupingUsed(false);
    return format.format(magnitude) + ((unit == null || unit.isEmpty()) ? "" : "," + getUnit());
}
 
开发者ID:gdl-lang,项目名称:gdl2,代码行数:12,代码来源:DvQuantity.java

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

示例9: printPercent

import java.text.DecimalFormat; //导入方法依赖的package包/类
private String printPercent() {
    if(uploadedBytes == fileSize || fileSize == 0)
        return "100%";
    else {
        DecimalFormat bd = new DecimalFormat("0.00");
        return bd.format((uploadedBytes) * 100.0 / fileSize) + "%";
    }
}
 
开发者ID:hetianyi,项目名称:easy-sync,代码行数:9,代码来源:UploadMonitor.java

示例10: calcPower

import java.text.DecimalFormat; //导入方法依赖的package包/类
private String calcPower(double newSpeed) {
	double currSpeed = Double.parseDouble(speedField.getText());
	String strPow;
	double a;
	double Pow;
	DecimalFormat df = new DecimalFormat("#.####");
	if (newSpeed > currSpeed) {
		deactivateService();
               	newSpeed = newSpeed * 0.44704;
		Pow = newSpeed * ((meanAccel * emptyMass) + (emptyMass * mu * g * Math.cos(theta)));
		strPow = df.format(Pow/1000) + "";
		a = .5 * 8052.9706;
		accelField.setText(df.format(a) + "");
	}
	else if (newSpeed == currSpeed) {
		deactivateService();
                newSpeed = newSpeed * 0.44704;
		Pow = newSpeed * emptyMass * Math.cos(theta) * g * mu;
		strPow = df.format(Pow/1000) + "";
		a = 0;
		accelField.setText(df.format(a) + "");
	}
	else {
		strPow = "0";
		activateService();
		a = -(1.2 + (Math.cos(theta) * mu * g));
		a = a *8052.9706;
		accelField.setText(df.format(a) + "");
	}
	return strPow;
}
 
开发者ID:kevingilboy,项目名称:COE1186,代码行数:32,代码来源:TrainC.java

示例11: weightConversion_Grams_To_Ounces

import java.text.DecimalFormat; //导入方法依赖的package包/类
public String weightConversion_Grams_To_Ounces(double grams){
	
	DecimalFormat myDF = new DecimalFormat("#.##");
	double ounces;
	String textOunces;
	ounces = (grams/28.34952);
	textOunces = myDF.format(ounces);
	return textOunces;
	
}
 
开发者ID:dylanwaynefoster,项目名称:AleCulator2,代码行数:11,代码来源:CalcMethods.java

示例12: calculateTaxes

import java.text.DecimalFormat; //导入方法依赖的package包/类
public double calculateTaxes(){
	DecimalFormat df = new DecimalFormat("####0.00");
	
	String tax = df.format(0.0725*this.subTotal);
	this.taxes = Double.parseDouble(tax);
	return this.taxes;
}
 
开发者ID:axd164330,项目名称:Restaurant,代码行数:8,代码来源:ShoppingCart.java

示例13: formatFileSizeToString

import java.text.DecimalFormat; //导入方法依赖的package包/类
public static String formatFileSizeToString(long fileLen) {// 转换文件大小
    DecimalFormat df = new DecimalFormat("#.00");
    String fileSizeString = "";
    if (fileLen < 1024) {
        fileSizeString = df.format((double) fileLen) + "B";
    } else if (fileLen < 1048576) {
        fileSizeString = df.format((double) fileLen / 1024) + "K";
    } else if (fileLen < 1073741824) {
        fileSizeString = df.format((double) fileLen / 1048576) + "M";
    } else {
        fileSizeString = df.format((double) fileLen / 1073741824) + "G";
    }
    return fileSizeString;
}
 
开发者ID:jqjm,项目名称:Liteframework,代码行数:15,代码来源:FileUtil.java

示例14: displayTable

import java.text.DecimalFormat; //导入方法依赖的package包/类
@Override
  protected void displayTable(HttpServletResponse response) throws SQLException, IOException {
      response.setIntHeader("Refresh", 5);
      
  	// Append table that lists all persons
  	List<DSM> resultList = dsmDAO.selectAllEntries();
         	
  	
  	response.getWriter().println(
              "<p><center><table width=70% border=\"1\"><tr><th colspan=\"1\"></th>" + "<th colspan=\"3\">" + (resultList.isEmpty() ? "" : resultList.size() + " ")
                      + "Employees in the EPM-BPC team</th>"
                      + "<th colspan=\"3\">" + "Smart Sorted</th></tr>");
      if (resultList.isEmpty()) {
          response.getWriter().println("<tr><td colspan=\"4\">Database is empty</td></tr>");
      } else {
          response.getWriter().println("<tr><th>#</th><th>Name</th><th>Assign</th><th>Remove</th><th>Amount</th><th>Total</th><th>AVG Q-DAY</th></tr>");
      }
      IXSSEncoder xssEncoder = XSSEncoder.getInstance();
      int index = 1;
      Collections.sort(resultList); 
   
      // Add [qm assign] button
  	response.getWriter().println("<p><center> Click here &#8594;  <input type=\"submit\" onclick=\"return window.prompt('Copy to clipboard: ','[EPM_QM_ASSIGNED]')\" value=\"[EPM_QM_ASSIGNED]\"></center></p>");
      
      int dsmIncidents = 0;
      for (DSM dsm : resultList) {
      	// Graham = 4, Marc = 10
      	if (dsm.getId() == 4 || dsm.getId()==10) {
      		// Calculate incident number
      		dsmIncidents += dsm.getDsm();
      		
       	// Get score
       	String score = "0";
      		DecimalFormat df = new DecimalFormat("#.###");
      		score = df.format(((double)dsm.getSum()) / QueueDays.hash.get(dsm.getName()));
       	
       	String pop = dsm.getName() + " has been +1, please go for assign.";
       	String link = "<td><center><form action=\"" + LINKNAME + "?Id="+ dsm.getId() + "&operation=add\" method=\"post\">" + "<input type=\"submit\" onclick=\"return window.prompt('" + pop + " Copy to clipboard: Ctrl+C, Enter','" + dsm.getiNumber() + "')\" value=\"Add\" />" + "</form></center></td>";
       	
       	if (dsm.getSum() < FIXEDVALUE) {
       		response.getWriter().println("<tr><td height=\"30\"><center>" + (index++) + "</center></td>");
        	if (index == 2) {
        		response.getWriter().println("<td height=\"30\"><center><mark><b>" + xssEncoder.encodeHTML(dsm.getName()+" ("+dsm.getiNumber()+")") + "</b></mark></center></td>");
        	} else {
        		response.getWriter().println("<td height=\"30\"><center>" + xssEncoder.encodeHTML(dsm.getName()+" ("+dsm.getiNumber()+")") + "</center></td>");
        	}
       		response.getWriter().println(link); 
        	response.getWriter().println("<td><center><form action=\"" + LINKNAME + "?Id="+ dsm.getId() + "&operation=decrease\" method=\"post\">" + "<input type=\"submit\" value=\"Delete\" />" + "</form></center></td>"); 
        	response.getWriter().println("<td height=\"30\"><center>" + dsm.getDsm() + "</center></td>");
			response.getWriter().println("<td height=\"30\"><center>" + dsm.getSum() + "</center></td>" + "<td height=\"30\"><center>" + score + "</center></td>");
       	} else {
        	response.getWriter().println("<tr><td height=\"30\"><center>" + (index++) + "</center></td>");
        	response.getWriter().println("<td height=\"30\"><center>" + xssEncoder.encodeHTML(dsm.getName() + ": UNAVAILABLE") + "</center></td>");
        	response.getWriter().println("<td><center>"+ xssEncoder.encodeHTML("N/A") + "</center></td>"); 
        	response.getWriter().println("<td><center>"+ xssEncoder.encodeHTML("N/A") + "</center></td>"); 
        	response.getWriter().println("<td height=\"30\"><center>" + dsm.getDsm() + "</center></td>");
			response.getWriter().println("<td height=\"30\"><center>" + (dsm.getSum()-FIXEDVALUE) + "</center></td>");
		}
       	
		response.getWriter().println("</tr>");
      	}
      }
      
      
response.getWriter().println("</table></center></p>");

response.getWriter().println("<p><center>DSM has <mark>" + dsmIncidents + "</mark> incidents" + "</center></p>");
response.getWriter().println("</body>");
  
// Home button
response.getWriter().println("<p><center><form action=\"" + "nw" + "\" method=\"get\">" + "<input type=\"submit\" value=\"Return to Home\" />" + "</form></center></p>");
      	       
  }
 
开发者ID:qianyilun,项目名称:Queue-Manager-Cloud-Dispatcher,代码行数:74,代码来源:PersistenceWithDSM.java

示例15: toFileSizeString

import java.text.DecimalFormat; //导入方法依赖的package包/类
public static String toFileSizeString(long fileSize) {
    DecimalFormat df = new DecimalFormat("0.00");
    String fileSizeString;
    if (fileSize < KB) {
        fileSizeString = fileSize + "B";
    } else if (fileSize < MB) {
        fileSizeString = df.format((double) fileSize / KB) + "K";
    } else if (fileSize < GB) {
        fileSizeString = df.format((double) fileSize / MB) + "M";
    } else {
        fileSizeString = df.format((double) fileSize / GB) + "G";
    }
    return fileSizeString;
}
 
开发者ID:fengdongfei,项目名称:CXJPadProject,代码行数:15,代码来源:ConvertUtils.java


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