List of usage examples for java.text DecimalFormat getDecimalFormatSymbols
public DecimalFormatSymbols getDecimalFormatSymbols()
From source file:ArabicDigitsI18N.java
public ArabicDigitsI18N() { DecimalFormat df = (DecimalFormat) NumberFormat.getInstance(); DecimalFormatSymbols dfs = df.getDecimalFormatSymbols(); dfs.setZeroDigit('\u0660'); df.setDecimalFormatSymbols(dfs);/* w ww .j av a2s . co m*/ JLabel label = new JLabel(df.format(1234567.89)); label.setFont(new Font("Lucida Sans", Font.PLAIN, 22)); add(label); }
From source file:Main.java
public Main() { DecimalFormat df = (DecimalFormat) NumberFormat.getInstance(); DecimalFormatSymbols dfs = df.getDecimalFormatSymbols(); dfs.setZeroDigit('\u0660'); df.setDecimalFormatSymbols(dfs);/*from ww w . ja va 2 s . co m*/ JLabel label = new JLabel(df.format(1234567.89)); label.setFont(new Font("Lucida Sans", Font.PLAIN, 22)); add(label); }
From source file:com.ocs.dynamo.ui.converter.CurrencyBigDecimalConverter.java
@Override protected DecimalFormat constructFormat(Locale locale) { // ignore the locale that is passed as a parameter, and use the default // locale instead so // that the number formatting is always the same DecimalFormat nf = (DecimalFormat) DecimalFormat.getCurrencyInstance(locale); DecimalFormatSymbols s = nf.getDecimalFormatSymbols(); s.setCurrencySymbol(currencySymbol); nf.setDecimalFormatSymbols(s);//w w w. j a va2 s . com return nf; }
From source file:nl.strohalm.cyclos.utils.conversion.UnitsConverter.java
public UnitsConverter(final String pattern, final DecimalFormat numberFormat) { super(BigDecimal.class, numberFormat); this.pattern = StringUtils.replace(pattern, "#amount#", "{0}"); final DecimalFormatSymbols symbols = numberFormat.getDecimalFormatSymbols(); decimalSeparator = symbols.getDecimalSeparator(); groupingSeparator = symbols.getGroupingSeparator(); }
From source file:com.ancientprogramming.fixedformat4j.format.impl.AbstractDecimalFormatter.java
public String asString(T obj, FormatInstructions instructions) { BigDecimal roundedValue = null; int decimals = instructions.getFixedFormatDecimalData().getDecimals(); if (obj != null) { BigDecimal value = obj instanceof BigDecimal ? (BigDecimal) obj : BigDecimal.valueOf(obj.doubleValue()); RoundingMode roundingMode = instructions.getFixedFormatDecimalData().getRoundingMode(); roundedValue = value.setScale(decimals, roundingMode); if (LOG.isDebugEnabled()) { LOG.debug("Value before rounding = '" + value + "', value after rounding = '" + roundedValue + "', decimals = " + decimals + ", rounding mode = " + roundingMode); }/* w w w .jav a2 s. com*/ } DecimalFormat formatter = new DecimalFormat(); formatter.setDecimalSeparatorAlwaysShown(true); formatter.setMaximumFractionDigits(decimals); char decimalSeparator = formatter.getDecimalFormatSymbols().getDecimalSeparator(); char groupingSeparator = formatter.getDecimalFormatSymbols().getGroupingSeparator(); String zeroString = "0" + decimalSeparator + "0"; String rawString = roundedValue != null ? formatter.format(roundedValue) : zeroString; if (LOG.isDebugEnabled()) { LOG.debug("rawString: " + rawString + " - G[" + groupingSeparator + "] D[" + decimalSeparator + "]"); } rawString = rawString.replaceAll("\\" + groupingSeparator, ""); boolean useDecimalDelimiter = instructions.getFixedFormatDecimalData().isUseDecimalDelimiter(); String beforeDelimiter = rawString.substring(0, rawString.indexOf(decimalSeparator)); String afterDelimiter = rawString.substring(rawString.indexOf(decimalSeparator) + 1, rawString.length()); if (LOG.isDebugEnabled()) { LOG.debug("beforeDelimiter[" + beforeDelimiter + "], afterDelimiter[" + afterDelimiter + "]"); } //trim decimals afterDelimiter = StringUtils.substring(afterDelimiter, 0, decimals); afterDelimiter = StringUtils.rightPad(afterDelimiter, decimals, '0'); String delimiter = useDecimalDelimiter ? "" + instructions.getFixedFormatDecimalData().getDecimalDelimiter() : ""; String result = beforeDelimiter + delimiter + afterDelimiter; if (LOG.isDebugEnabled()) { LOG.debug("result[" + result + "]"); } return result; }
From source file:chibi.gemmaanalysis.CorrelationAnalysisCLI.java
@Override protected Exception doWork(String[] args) { Exception exc = processCommandLine(args); if (exc != null) { return exc; }/*from w w w . j a va 2 s .c om*/ Collection<Gene> queryGenes, targetGenes; try { queryGenes = getQueryGenes(); targetGenes = getTargetGenes(); } catch (IOException e) { return e; } // calculate matrices CoexpressionMatrices matrices = coexpressionAnalysisService.calculateCoexpressionMatrices( expressionExperiments, queryGenes, targetGenes, filterConfig, CorrelationMethod.SPEARMAN); DenseDouble3dMatrix<Gene, Gene, BioAssaySet> correlationMatrix = matrices.getCorrelationMatrix(); // DenseDoubleMatrix3DNamed sampleSizeMatrix = matrices // .getSampleSizeMatrix(); // DoubleMatrixNamed maxCorrelationMatrix = coexpressionAnalysisService // .getMaxCorrelationMatrix(correlationMatrix, kMax); // DoubleMatrixNamed pValMatrix = coexpressionAnalysisService // .calculateMaxCorrelationPValueMatrix(maxCorrelationMatrix, // kMax, ees); // DoubleMatrixNamed effectSizeMatrix = coexpressionAnalysisService // .calculateEffectSizeMatrix(correlationMatrix, sampleSizeMatrix); // get row/col name maps Map<Gene, String> geneNameMap = matrices.getGeneNameMap(); Map<ExpressionExperiment, String> eeNameMap = matrices.getEeNameMap(); DecimalFormat formatter = (DecimalFormat) NumberFormat.getNumberInstance(Locale.US); formatter.applyPattern("0.0000"); DecimalFormatSymbols symbols = formatter.getDecimalFormatSymbols(); symbols.setNaN("NaN"); formatter.setDecimalFormatSymbols(symbols); try { MatrixWriter<Gene, Gene> matrixOut; matrixOut = new MatrixWriter<Gene, Gene>(outFilePrefix + ".corr.txt", formatter); matrixOut.setSliceNameMap(eeNameMap); matrixOut.setRowNameMap(geneNameMap); matrixOut.setColNameMap(geneNameMap); matrixOut.writeMatrix(correlationMatrix, false); try (PrintWriter out = new PrintWriter(new FileWriter(outFilePrefix + ".corr.row_names.txt"));) { List<Gene> rows = correlationMatrix.getRowNames(); for (Gene row : rows) { out.println(row); } } try (PrintWriter out = new PrintWriter(new FileWriter(outFilePrefix + ".corr.col_names.txt"));) { Collection<BioAssaySet> cols = correlationMatrix.getSliceNames(); for (BioAssaySet bas : cols) { ExpressionExperiment ee = (ExpressionExperiment) bas; out.println(ee.getShortName()); } } } catch (IOException e) { return e; } // out = new MatrixWriter(outFilePrefix + ".max_corr.txt", formatter, // geneNameMap, geneNameMap); // out.writeMatrix(maxCorrelationMatrix, true); // out.close(); // // out = new MatrixWriter(outFilePrefix + ".max_corr.pVal.txt", // formatter, geneNameMap, geneNameMap); // out.writeMatrix(pValMatrix, true); // out.close(); // // out = new MatrixWriter(outFilePrefix + ".effect_size.txt", // formatter, geneNameMap, geneNameMap); // out.writeMatrix(effectSizeMatrix, true); // out.close(); return null; }
From source file:org.apache.cocoon.template.instruction.FormatNumber.java
private void setCurrency(NumberFormat formatter, String currencyCode, String currencySymbol) throws Exception { String code = null;/*from ww w. ja v a 2 s . c om*/ String symbol = null; if (currencyCode == null) { if (currencySymbol == null) { return; } symbol = currencySymbol; } else if (currencySymbol != null) { if (currencyClass != null) { code = currencyCode; } else { symbol = currencySymbol; } } else if (currencyClass != null) { code = currencyCode; } else { symbol = currencyCode; } if (code != null) { Object[] methodArgs = new Object[1]; /* * java.util.Currency.getInstance() */ Method m = currencyClass.getMethod("getInstance", new Class[] { String.class }); methodArgs[0] = code; Object currency = m.invoke(null, methodArgs); /* * java.text.NumberFormat.setCurrency() */ Class[] paramTypes = new Class[1]; paramTypes[0] = currencyClass; Class numberFormatClass = Class.forName("java.text.NumberFormat"); m = numberFormatClass.getMethod("setCurrency", paramTypes); methodArgs[0] = currency; m.invoke(formatter, methodArgs); } else { /* * Let potential ClassCastException propagate up (will almost never * happen) */ DecimalFormat df = (DecimalFormat) formatter; DecimalFormatSymbols dfs = df.getDecimalFormatSymbols(); dfs.setCurrencySymbol(symbol); df.setDecimalFormatSymbols(dfs); } }
From source file:org.mifos.platform.accounting.service.AccountingDataCacheManager.java
private String parseNumber(String number) { // FIXME should use this from common util StringBuilder pattern = new StringBuilder(); DecimalFormat decimalFormat = (DecimalFormat) DecimalFormat.getCurrencyInstance(Locale.ENGLISH); for (Short i = 0; i < DIGITS_BEFORE_DECIMAL; i++) { pattern.append('#'); }/*from w w w . jav a 2s . c o m*/ pattern.append(decimalFormat.getDecimalFormatSymbols().getDecimalSeparator()); for (short i = 0; i < getDigitsAfterDecimal(); i++) { pattern.append('#'); } decimalFormat.applyLocalizedPattern(pattern.toString()); decimalFormat.setDecimalSeparatorAlwaysShown(false); decimalFormat.setMinimumFractionDigits(getDigitsAfterDecimal()); return decimalFormat.format(Double.parseDouble(number)); }
From source file:org.talend.dataprep.transformation.actions.math.ChangeNumberFormat.java
/** * Return the custom format out of the parameters. * * @param parameters the action parameters. * @return the custom format out of the parameters. *//* w w w . j a va 2s . co m*/ private NumberFormat getCustomFormat(Map<String, String> parameters) { final DecimalFormat decimalFormat = new DecimalFormat(parameters.get(TARGET_PATTERN + "_" + CUSTOM)); DecimalFormatSymbols decimalFormatSymbols = decimalFormat.getDecimalFormatSymbols(); String decimalSeparator = getCustomizableParam(TARGET + DECIMAL + SEPARATOR, parameters); if (!StringUtils.isEmpty(decimalSeparator)) { decimalFormatSymbols.setDecimalSeparator(decimalSeparator.charAt(0)); } String groupingSeparator = getCustomizableParam(TARGET + GROUPING + SEPARATOR, parameters); if (StringUtils.isEmpty(groupingSeparator) || groupingSeparator.equals(decimalSeparator)) { decimalFormat.setGroupingUsed(false); } else { decimalFormatSymbols.setGroupingSeparator(groupingSeparator.charAt(0)); } decimalFormat.setDecimalFormatSymbols(decimalFormatSymbols); return decimalFormat; }
From source file:org.openehr.rm.datatypes.quantity.DvQuantity.java
/** * string form displayable for humans/*from w ww. j av a 2 s . c o m*/ * * @return string presentation */ 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); String tmp = format.format(magnitude) + (StringUtils.isEmpty(getUnits()) ? "" : "," + getUnits()); return tmp; }