Java Code Examples for java.text.DecimalFormat#setPositivePrefix()
The following examples show how to use
java.text.DecimalFormat#setPositivePrefix() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GenericConverter.java From sailfish-core with Apache License 2.0 | 6 votes |
public static <T extends Number> byte[] convertSignedNumericToArray(int length, T value, int precision ) { // Pattern for fractional part char[] arrFractional = new char[precision]; Arrays.fill(arrFractional, '0'); // Pattern for mantissa char[] arrMantissa = new char[length - 1 - precision ]; Arrays.fill(arrMantissa, '0'); String patternDesired = String.format( "%s.%s", new String(arrMantissa), new String(arrFractional)); DecimalFormat formatter = new DecimalFormat(patternDesired ); formatter.setPositivePrefix("+"); formatter.setNegativePrefix("-"); formatter.setGroupingUsed(false); String formattedValue = formatter.format(value); DecimalFormatSymbols decimalFormatSymbol = formatter.getDecimalFormatSymbols(); formattedValue = formattedValue.replace(String.valueOf(decimalFormatSymbol.getDecimalSeparator()), ""); return formattedValue.getBytes(charsetISO_8859); }
Example 2
Source File: GenericConverter.java From sailfish-core with Apache License 2.0 | 6 votes |
public static <T extends Number> byte[] convertUnsignedNumericToArray(int length, T value, int precision ) { // Pattern for fractional part char[] arrFractional = new char[precision]; Arrays.fill(arrFractional, '0'); // Pattern for mantissa char[] arrMantissa = new char[length - precision ]; Arrays.fill(arrMantissa, '0'); String patternDesired = String.format( "%s.%s", new String(arrMantissa), new String(arrFractional)); DecimalFormat formatter = new DecimalFormat(patternDesired ); formatter.setPositivePrefix(""); formatter.setNegativePrefix(""); formatter.setGroupingUsed(false); String formattedValue = formatter.format(value); DecimalFormatSymbols decimalFormatSymbol = formatter.getDecimalFormatSymbols(); formattedValue = formattedValue.replace(String.valueOf(decimalFormatSymbol.getDecimalSeparator()), ""); return formattedValue.getBytes(charsetISO_8859); }
Example 3
Source File: FloatingPointFormat.java From tsml with GNU General Public License v3.0 | 5 votes |
public FloatingPointFormat( int w, int d ) { width = w; decimal = d; nf = new DecimalFormat( pattern(w, d) ); nf.setPositivePrefix(" "); nf.setNegativePrefix("-"); }
Example 4
Source File: ExponentialFormat.java From tsml with GNU General Public License v3.0 | 5 votes |
public ExponentialFormat( int digits, int exp, boolean sign, boolean trailing ) { this.digits = digits; this.exp = exp; this.sign = sign; this.trailing = trailing; nf = new DecimalFormat( pattern() ); nf.setPositivePrefix("+"); nf.setNegativePrefix("-"); }
Example 5
Source File: FloatingPointFormat.java From KEEL with GNU General Public License v3.0 | 5 votes |
/** * Constructor. Creates a FloatingPointFormat with the given values width and decimal size. * @param w width given. * @param d decimal size given. */ public FloatingPointFormat( int w, int d ) { width = w; decimal = d; nf = new DecimalFormat( pattern(w, d) ); nf.setPositivePrefix(" "); nf.setNegativePrefix("-"); }
Example 6
Source File: ExponentialFormat.java From KEEL with GNU General Public License v3.0 | 5 votes |
/** ** Constructor. Creates a ExponentialFormat with the given arguments. * @param digits given base size. * @param exp given exponent size. * @param sign given sign flag. * @param trailing given trailing flag. */ public ExponentialFormat( int digits, int exp, boolean sign, boolean trailing ) { this.digits = digits; this.exp = exp; this.sign = sign; this.trailing = trailing; nf = new DecimalFormat( pattern() ); nf.setPositivePrefix("+"); nf.setNegativePrefix("-"); }
Example 7
Source File: EBIMatrix.java From ReactionDecoder with GNU Lesser General Public License v3.0 | 5 votes |
/** * Return a matrix as a String. * * @return */ @Override public synchronized String toString() { if ((rows <= 0) || (columns <= 0)) { return "[]"; } int i, j; DecimalFormat format = new DecimalFormat("00.0000"); format.setPositivePrefix("+"); StringBuilder str = new StringBuilder(); for (i = 0; i < (rows - 1); i++) { for (j = 0; j < (columns - 1); j++) { if (round(matrix[i][j] * 10000) != 0) { str.append(format.format(matrix[i][j])).append(" "); } else { str.append("-------- "); } } if (round(matrix[i][columns - 1] * 10000) != 0) { str.append(format.format(matrix[i][columns - 1])).append(NEW_LINE); } else { str.append("--------").append(NEW_LINE); } } for (j = 0; j < (columns - 1); j++) { if (round(matrix[rows - 1][j] * 10000) != 0) { str.append(format.format(matrix[rows - 1][j])).append(" "); } else { str.append("-------- "); } } if (round(matrix[rows - 1][columns - 1] * 10000) != 0) { str.append(format.format(matrix[rows - 1][columns - 1])); } else { str.append("-------- "); } return str.toString(); }
Example 8
Source File: DecimalFormatTest.java From j2objc with Apache License 2.0 | 5 votes |
public void test_setPositivePrefix() throws Exception { DecimalFormat format = new DecimalFormat(); assertEquals("", format.getPositivePrefix()); format.setPositivePrefix("PosPrf"); assertEquals("PosPrf", format.getPositivePrefix()); assertTrue(format.parse("PosPrf123.45").doubleValue() == 123.45); format.setPositivePrefix(""); assertEquals("", format.getPositivePrefix()); format.setPositivePrefix(null); assertNull(format.getPositivePrefix()); }
Example 9
Source File: DecimalFormatTest.java From j2objc with Apache License 2.0 | 4 votes |
public void test_getPositivePrefix() { DecimalFormat df = new DecimalFormat(); df.setPositivePrefix("++"); assertTrue("Incorrect positive prefix", df.getPositivePrefix().equals("++")); }