Java Code Examples for java.text.DecimalFormat#setNegativePrefix()
The following examples show how to use
java.text.DecimalFormat#setNegativePrefix() .
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: DecimalFormatTest.java From j2objc with Apache License 2.0 | 5 votes |
public void test_setNegativePrefix() throws Exception { DecimalFormat format = new DecimalFormat(); assertEquals("-", format.getNegativePrefix()); format.setNegativePrefix("NegPrf"); assertEquals("NegPrf", format.getNegativePrefix()); assertTrue(format.parse("NegPrf123.45").doubleValue() == -123.45); format.setNegativePrefix(""); assertEquals("", format.getNegativePrefix()); format.setNegativePrefix(null); assertNull(format.getNegativePrefix()); }
Example 8
Source File: DailyBarChart.java From AndroidApp with GNU Affero General Public License v3.0 | 4 votes |
public Chart2ValueFormatter() { mFormat = new DecimalFormat("###,###,##0.0"); // use one decimal mFormat.setNegativePrefix(""); }
Example 9
Source File: DecimalFormatTest.java From j2objc with Apache License 2.0 | 4 votes |
public void test_getNegativePrefix() { DecimalFormat df = new DecimalFormat(); df.setNegativePrefix("--"); assertTrue("Incorrect negative prefix", df.getNegativePrefix().equals("--")); }