List of usage examples for java.text NumberFormat format
public final String format(long number)
From source file:gmgen.plugin.PlayerCharacterOutput.java
String getEquipmentList() { StringBuilder sb = new StringBuilder(); boolean firstLine = true; for (Equipment eq : pc.getEquipmentListInOutputOrder()) { if (!firstLine) { sb.append(", "); }//from ww w . j a v a 2 s .com firstLine = false; NumberFormat formater = new DecimalFormat(); formater.setMaximumFractionDigits(1); formater.setMinimumFractionDigits(0); sb.append(formater.format(eq.getQty())).append(" ").append(eq.getName()); } return sb.toString(); }
From source file:com.codebutler.farebot.transit.suica.SuicaTrip.java
@Override public String getFareString() { NumberFormat format = NumberFormat.getCurrencyInstance(Locale.JAPAN); format.setMaximumFractionDigits(0);/*from ww w . j av a 2 s. c om*/ if (mFare < 0) { return "+" + format.format(-mFare); } else { return format.format(mFare); } }
From source file:com.clustercontrol.sql.factory.RunMonitorSqlString.java
/** * SQL?/*from w w w.j a v a 2 s . c o m*/ * * @param facilityId ID * @return ???????true */ @Override public boolean collect(String facilityId) { // set Generation Date if (m_now != null) { m_nodeDate = m_now.getTime(); } boolean result = false; AccessDB access = null; ResultSet rSet = null; String url = m_url; try { // ???URL?? if (nodeInfo != null && nodeInfo.containsKey(facilityId)) { Map<String, String> nodeParameter = RepositoryUtil.createNodeParameter(nodeInfo.get(facilityId)); StringBinder strbinder = new StringBinder(nodeParameter); url = strbinder.bindParam(m_url); if (m_log.isTraceEnabled()) m_log.trace("jdbc request. (nodeInfo = " + nodeInfo + ", facilityId = " + facilityId + ", url = " + url + ")"); } // DB?? access = new AccessDB(m_jdbcDriver, url, m_user, m_password); // SQL????? if (m_query.length() >= 6) { String work = m_query.substring(0, 6); if (work.equalsIgnoreCase("SELECT")) { rSet = access.read(m_query); //1?1?? rSet.first(); m_value = rSet.getString(1); //? rSet.last(); int number = rSet.getRow(); NumberFormat numberFormat = NumberFormat.getNumberInstance(); m_messageOrg = MessageConstant.RECORD_VALUE.getMessage() + " : " + m_value + ", " + MessageConstant.RECORDS_NUMBER.getMessage() + " : " + numberFormat.format(number); m_messageOrg += "\n" + MessageConstant.CONNECTION_URL.getMessage() + " : " + url; result = true; } else { //SELECT? m_log.info("collect(): " + MessageConstant.MESSAGE_PLEASE_SET_SELECT_STATEMENT_IN_SQL.getMessage()); m_unKnownMessage = MessageConstant.MESSAGE_PLEASE_SET_SELECT_STATEMENT_IN_SQL.getMessage(); m_messageOrg = MessageConstant.SQL_STRING.getMessage() + " : " + m_query; m_messageOrg += "\n" + MessageConstant.CONNECTION_URL.getMessage() + " : " + url; } } else { //SELECT? m_log.info("collect(): " + MessageConstant.MESSAGE_PLEASE_SET_SELECT_STATEMENT_IN_SQL.getMessage()); m_unKnownMessage = MessageConstant.MESSAGE_PLEASE_SET_SELECT_STATEMENT_IN_SQL.getMessage(); m_messageOrg = MessageConstant.SQL_STRING.getMessage() + " : " + m_query; m_messageOrg += "\n" + MessageConstant.CONNECTION_URL.getMessage() + " : " + url; } } catch (ClassNotFoundException e) { m_log.debug("collect() : " + e.getClass().getSimpleName() + ", " + e.getMessage()); m_unKnownMessage = MessageConstant.MESSAGE_CANNOT_FIND_JDBC_DRIVER.getMessage(); m_messageOrg = MessageConstant.SQL_STRING.getMessage() + " : " + m_query + " (" + e.getMessage() + ")"; m_messageOrg += "\n" + MessageConstant.CONNECTION_URL.getMessage() + " : " + url; } catch (SQLException e) { // SQL m_log.info("collect() : " + e.getClass().getSimpleName() + ", " + e.getMessage()); m_unKnownMessage = MessageConstant.MESSAGE_FAILED_TO_EXECUTE_SQL.getMessage(); m_messageOrg = MessageConstant.SQL_STRING.getMessage() + " : " + m_query + " (" + e.getMessage() + ")"; m_messageOrg += "\n" + MessageConstant.CONNECTION_URL.getMessage() + " : " + url; } finally { try { if (rSet != null) { rSet.close(); } if (access != null) { // DB? access.terminate(); } } catch (SQLException e) { m_log.warn("collect() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); } } return result; }
From source file:com.clustercontrol.sql.factory.RunMonitorSql.java
/** * SQL?//from w ww. j a va 2 s . c o m * * @param facilityId ID * @return ???????true */ @Override public boolean collect(String facilityId) { // set Generation Date if (m_now != null) { m_nodeDate = m_now.getTime(); } boolean result = false; AccessDB access = null; ResultSet rSet = null; String url = m_url; try { // ???URL?? if (nodeInfo != null && nodeInfo.containsKey(facilityId)) { Map<String, String> nodeParameter = RepositoryUtil.createNodeParameter(nodeInfo.get(facilityId)); StringBinder strbinder = new StringBinder(nodeParameter); url = strbinder.bindParam(m_url); if (m_log.isTraceEnabled()) m_log.trace("jdbc request. (nodeInfo = " + nodeInfo + ", facilityId = " + facilityId + ", url = " + url + ")"); } // DB?? access = new AccessDB(m_jdbcDriver, url, m_user, m_password); // SQL????? if (m_query.length() >= 6) { String work = m_query.substring(0, 6); if (work.equalsIgnoreCase("SELECT")) { rSet = access.read(m_query); //1?1?? rSet.first(); double count = rSet.getDouble(1); m_value = count; //? rSet.last(); int number = rSet.getRow(); NumberFormat numberFormat = NumberFormat.getNumberInstance(); m_message = MessageConstant.SELECT_VALUE.getMessage() + " : " + m_value; m_messageOrg = MessageConstant.RECORD_VALUE.getMessage() + " : " + numberFormat.format(m_value) + ", " + MessageConstant.RECORDS_NUMBER.getMessage() + " : " + numberFormat.format(number); m_messageOrg += "\n" + MessageConstant.CONNECTION_URL.getMessage() + " : " + url; result = true; } else { //SELECT? m_log.info("collect(): " + MessageConstant.MESSAGE_PLEASE_SET_SELECT_STATEMENT_IN_SQL.getMessage()); m_unKnownMessage = MessageConstant.MESSAGE_PLEASE_SET_SELECT_STATEMENT_IN_SQL.getMessage(); m_messageOrg = MessageConstant.SQL_STRING.getMessage() + " : " + m_query; m_messageOrg += "\n" + MessageConstant.CONNECTION_URL.getMessage() + " : " + url; } } else { //SELECT? m_log.info("collect(): " + MessageConstant.MESSAGE_PLEASE_SET_SELECT_STATEMENT_IN_SQL.getMessage()); m_unKnownMessage = MessageConstant.MESSAGE_PLEASE_SET_SELECT_STATEMENT_IN_SQL.getMessage(); m_messageOrg = MessageConstant.SQL_STRING.getMessage() + " : " + m_query; m_messageOrg += "\n" + MessageConstant.CONNECTION_URL.getMessage() + " : " + url; } } catch (ClassNotFoundException e) { m_log.debug("collect() : " + e.getClass().getSimpleName() + ", " + e.getMessage()); m_unKnownMessage = MessageConstant.MESSAGE_CANNOT_FIND_JDBC_DRIVER.getMessage(); m_messageOrg = MessageConstant.SQL_STRING.getMessage() + " : " + m_query + " (" + e.getMessage() + ")"; m_messageOrg += "\n" + MessageConstant.CONNECTION_URL.getMessage() + " : " + url; } catch (SQLException e) { // SQL m_log.info("collect() : " + e.getClass().getSimpleName() + ", " + e.getMessage()); m_unKnownMessage = MessageConstant.MESSAGE_FAILED_TO_EXECUTE_SQL.getMessage(); m_messageOrg = MessageConstant.SQL_STRING.getMessage() + " : " + m_query + " (" + e.getMessage() + ")"; m_messageOrg += "\n" + MessageConstant.CONNECTION_URL.getMessage() + " : " + url; } finally { try { if (rSet != null) { rSet.close(); } if (access != null) { // DB? access.terminate(); } } catch (SQLException e) { m_log.warn("collect() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); } } return result; }
From source file:com.skilrock.lms.web.accMgmt.common.AgentPaymentSubmit.java
public String agentPayment() throws Exception { logger.info("REQUEST_CASH_PAYMENT_SUBMIT-" + this); HttpSession session = null;//from www . j a v a2 s .c o m UserInfoBean userBean = null, agentInfoBean = null; String[] denoType = null; Connection con = null; try { session = getRequest().getSession(); userBean = (UserInfoBean) session.getAttribute("USER_INFO"); agentInfoBean = CommonMethods.fetchUserData(orgId); logger.info( "REQUEST_CASH_PAYMENT_SUBMIT-" + request.getAttribute("AUDIT_ID") + ":" + userBean.getUserId()); String currencySymbol = (String) ServletActionContext.getServletContext() .getAttribute("CURRENCY_SYMBOL"); logger.info("user_id is-" + userBean.getUserId()); ServletContext sc = ServletActionContext.getServletContext(); String isCREnable = (String) sc.getAttribute("IS_CASH_REGISTER"); if (totalAmount != cashAmnt) { throw new LMSException(LMSErrors.CASH_PAYMENT_INVALIDATE_DATA_ERROR_CODE, LMSErrors.CASH_PAYMENT_INVALIDATE_DATA_ERROR_MESSAGE); } if ("ACTIVE".equalsIgnoreCase(isCREnable)) { CashRegisterHelper drawerHelper = new CashRegisterHelper(); List<String> denoList = drawerHelper.getReceivedDenoList(); denoType = (String[]) denoList.toArray(new String[denoList.size()]); } con = DBConnect.getConnection(); con.setAutoCommit(false); int retOrgId = Integer.parseInt(retOrgName); int agentId = agentInfoBean.getUserId(); AgentPaymentSubmitHelper helper = new AgentPaymentSubmitHelper(); String autoGeneRecieptNoAndId = helper.submitCashAgentAmt(orgId, "AGENT", totalAmount, userBean.getUserId(), userBean.getUserOrgId(), userBean.getUserType(), denoType, multiples, retDenoType, retMultiples, con); if (orgType.equalsIgnoreCase("RETAILER")) { RetailerPaymentSubmitHelper retailerPaymentSubmit = new RetailerPaymentSubmitHelper(); autoGeneRecieptNoAndId = retailerPaymentSubmit.retailerCashPaySubmit(retOrgId, "RETAILER", retOrgId, totalAmount, agentId, orgId, "AGENT", con); } con.commit(); String[] autoGeneReceipt = autoGeneRecieptNoAndId.split("#"); String autoGeneRecieptNo = autoGeneReceipt[0]; int id = Integer.parseInt(autoGeneReceipt[1]); java.util.Date d = new java.util.Date(); SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); String generationTime = sdf.format(d.getTime()); logger.info("Generation time:" + generationTime); boolean isThermalRcptRequired = "true".equals((String) ServletActionContext.getServletContext() .getAttribute("IS_CASH_RCPT_ON_THERMAL_PRINTER")); if (isThermalRcptRequired) { NumberFormat nf = NumberFormat.getInstance(); nf.setMinimumFractionDigits(2); String amountCash = nf.format(totalAmount); String data = "data=0|txType=RECEIPT|address=" + CommonMethods.getOrgAddress(String.valueOf(userBean.getUserOrgId())) + "|genTime=" + generationTime + "|mode=Voucher|voucherNo=" + autoGeneRecieptNo + "|txDate=" + sdf.format(d.getTime()) + "|amount=" + amountCash + "|orgName=" + agentNameValue + "|ctr=200|parentOrgName=" + userBean.getOrgName() + "|curSymbol=" + currencySymbol; session.setAttribute("APP_DATA", data); } session.setAttribute("totalPay", totalAmount); session.setAttribute("orgName", agentNameValue); session.setAttribute("Receipt_Id", autoGeneRecieptNo); GraphReportHelper graphReportHelper = new GraphReportHelper(); if ("AGENT".equalsIgnoreCase(orgType)) { String parentOrgName = null; int userOrgID = 0; parentOrgName = userBean.getOrgName(); userOrgID = userBean.getUserOrgId(); graphReportHelper.createTextReportBO(id, parentOrgName, userOrgID, (String) session.getAttribute("ROOT_PATH")); } else { graphReportHelper.createTextReportAgent(id, (String) session.getAttribute("ROOT_PATH"), orgId, agentInfoBean.getOrgName()); } } catch (LMSException le) { logger.info("RESPONSE_CASH_PAYMENT_SUBMIT-: ErrorCode:" + le.getErrorCode() + " ErrorMessage:" + le.getErrorMessage()); request.setAttribute("LMS_EXCEPTION", le.getErrorMessage()); return "applicationException"; } catch (Exception e) { logger.error("Exception", e); logger.info("RESPONSE_CASH_PAYMENT_SUBMIT-: ErrorCode:" + LMSErrors.GENERAL_EXCEPTION_ERROR_CODE + " ErrorMessage:" + LMSErrors.GENERAL_EXCEPTION_ERROR_MESSAGE); request.setAttribute("LMS_EXCEPTION", LMSErrors.GENERAL_EXCEPTION_ERROR_MESSAGE); return "applicationException"; } finally { try { if (con != null) { con.close(); } } catch (SQLException e) { e.printStackTrace(); } } return SUCCESS; }
From source file:clus.statistic.RegressionStatBase.java
public String getArrayOfStatistic() { NumberFormat fr = ClusFormat.SIX_AFTER_DOT; StringBuffer buf = new StringBuffer(); buf.append("["); for (int i = 0; i < m_NbAttrs; i++) { if (i != 0) buf.append(","); buf.append(fr.format(m_Means[i])); }/* w w w. j av a 2 s .c om*/ buf.append("]"); return buf.toString(); }
From source file:com.salesmanager.core.module.impl.application.currencies.GenericCurrencyModule.java
public String getMeasure(BigDecimal measure, String currencycode) throws Exception { NumberFormat nf = null; Locale locale = Locale.US; if (this.decimalPoint == ',') { locale = Locale.GERMAN;/*from ww w. jav a 2 s . c om*/ } nf = NumberFormat.getInstance(locale); nf.setMaximumFractionDigits(1); nf.setMinimumFractionDigits(1); measure.setScale(1, BigDecimal.ROUND_HALF_UP); return nf.format(measure); }
From source file:com.eyeq.pivot4j.ui.aggregator.AbstractAggregator.java
/** * @see com.eyeq.pivot4j.ui.aggregator.Aggregator#getFormattedValue(com.eyeq.pivot4j.ui.RenderContext) *//*from w w w . j a va 2 s . co m*/ public String getFormattedValue(RenderContext context) { Position position = getTargetPosition(context); Double value = getValue(position); NumberFormat format = getNumberFormat(position); if (value == null) { return null; } else if (format == null) { return Double.toString(value); } else { return format.format(value); } }
From source file:clus.statistic.RegressionStatBase.java
public String getDebugString() { NumberFormat fr = ClusFormat.THREE_AFTER_DOT; StringBuffer buf = new StringBuffer(); buf.append("["); for (int i = 0; i < m_NbAttrs; i++) { if (i != 0) buf.append(","); buf.append(fr.format(getMean(i))); }//from w w w .j a v a 2s.com buf.append("]"); buf.append("["); for (int i = 0; i < m_NbAttrs; i++) { if (i != 0) buf.append(","); buf.append(fr.format(getVariance(i))); } buf.append("]"); return buf.toString(); }
From source file:de.tor.tribes.ui.algo.TimeFrameVisualizer.java
private void renderDayMarkers(long pStart, long pEnd, Graphics2D pG2D) { Date d = new Date(pStart); d = DateUtils.setHours(d, 0);/* w w w. j a v a 2s. co m*/ d = DateUtils.setMinutes(d, 0); d = DateUtils.setSeconds(d, 0); d = DateUtils.setMilliseconds(d, 0); for (long mark = d.getTime(); mark <= pEnd; mark += DateUtils.MILLIS_PER_HOUR) { int markerPos = Math.round((mark - pStart) / DateUtils.MILLIS_PER_MINUTE); pG2D.setColor(Color.YELLOW); pG2D.fillRect(markerPos, 20, 2, 10); pG2D.setColor(Color.WHITE); pG2D.setFont(pG2D.getFont().deriveFont(Font.BOLD, 10.0f)); pG2D.fillRect(markerPos - 5, 15, 12, 10); pG2D.setColor(Color.BLACK); Calendar cal = Calendar.getInstance(); cal.setTime(new Date(mark)); NumberFormat f = NumberFormat.getNumberInstance(); f.setMinimumIntegerDigits(2); f.setMaximumFractionDigits(2); pG2D.drawString(f.format(cal.get(Calendar.HOUR_OF_DAY)), markerPos - 5, 23); } long currentDay = d.getTime(); while (currentDay < pEnd) { currentDay += DateUtils.MILLIS_PER_DAY; int markerPos = Math.round((currentDay - pStart) / DateUtils.MILLIS_PER_MINUTE); pG2D.setColor(new Color(123, 123, 123)); pG2D.fillRect(markerPos, 15, 3, 30); SimpleDateFormat f = new SimpleDateFormat("dd.MM.yy"); String dayLabel = f.format(currentDay); Rectangle2D labelBounds = pG2D.getFontMetrics().getStringBounds(dayLabel, pG2D); pG2D.setColor(Color.YELLOW); int labelWidth = (int) labelBounds.getWidth() + 5; pG2D.fillRect(markerPos - (int) Math.rint(labelWidth / 2), 15, labelWidth, 10); pG2D.setColor(Color.BLACK); pG2D.setFont(pG2D.getFont().deriveFont(Font.BOLD, 10.0f)); pG2D.drawString(dayLabel, markerPos - (int) Math.rint(labelWidth / 2) + 2, 23); } }