Java Code Examples for java.text.DecimalFormat.setDecimalFormatSymbols()

The following are Jave code examples for showing how to use setDecimalFormatSymbols() of the java.text.DecimalFormat class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: micrometer   File: DoubleFormat.java   Source Code and License Vote up 6 votes
@Override
protected NumberFormat initialValue() {

    // Always create the formatter for the US locale in order to avoid this bug:
    // https://github.com/indeedeng/java-dogstatsd-client/issues/3
    final NumberFormat numberFormatter = NumberFormat.getInstance(Locale.US);
    numberFormatter.setGroupingUsed(false);
    numberFormatter.setMaximumFractionDigits(6);

    // we need to specify a value for Double.NaN that is recognized by dogStatsD
    if (numberFormatter instanceof DecimalFormat) { // better safe than a runtime error
        final DecimalFormat decimalFormat = (DecimalFormat) numberFormatter;
        final DecimalFormatSymbols symbols = decimalFormat.getDecimalFormatSymbols();
        symbols.setNaN("NaN");
        decimalFormat.setDecimalFormatSymbols(symbols);
    }

    return numberFormatter;
}
 
Example 2
Project: EARLGREY   File: GeoAlgorithm.java   Source Code and License Vote up 6 votes
public static JSONArray cluster_simplfication(JSONArray coords, double tolerance){
	DecimalFormat df = new DecimalFormat("0.0000");
	DecimalFormatSymbols simbolos = new DecimalFormatSymbols();
	simbolos.setDecimalSeparator('.');
	df.setDecimalFormatSymbols(simbolos);
	double pivotx = coords.getDouble(0);
	double pivoty = coords.getDouble(1);
	JSONArray newcoords = new JSONArray();
	newcoords.put(new Float(df.format(pivotx)));
	newcoords.put(new Float(df.format(pivoty)));
	for(int i=2; i<coords.length(); i++){
		if(Math.sqrt(Math.pow((coords.getDouble(i)-pivotx), 2)+Math.pow((coords.getDouble(i+1)-pivoty), 2)) >= tolerance){
			pivotx = coords.getDouble(i);
			pivoty = coords.getDouble(i+1);
			newcoords.put(new Float(df.format(pivotx)));
			newcoords.put(new Float(df.format(pivoty)));
		}
		i++;
	}
	return newcoords;
}
 
Example 3
Project: openjdk-jdk10   File: TestShrinkAuxiliaryData.java   Source Code and License Vote up 6 votes
private void printTestInfo(int maxCacheSize) {

        DecimalFormat grouped = new DecimalFormat("000,000");
        DecimalFormatSymbols formatSymbols = grouped.getDecimalFormatSymbols();
        formatSymbols.setGroupingSeparator(' ');
        grouped.setDecimalFormatSymbols(formatSymbols);

        System.out.format(
                "Test will use %s bytes of memory of %s available%n"
                + "Available memory is %s with %d bytes pointer size - can save %s pointers%n"
                + "Max cache size: 2^%d = %s elements%n",
                grouped.format(ShrinkAuxiliaryDataTest.getMemoryUsedByTest()),
                grouped.format(Runtime.getRuntime().maxMemory()),
                grouped.format(Runtime.getRuntime().maxMemory()
                        - ShrinkAuxiliaryDataTest.getMemoryUsedByTest()),
                Unsafe.ADDRESS_SIZE,
                grouped.format((Runtime.getRuntime().freeMemory()
                        - ShrinkAuxiliaryDataTest.getMemoryUsedByTest())
                        / Unsafe.ADDRESS_SIZE),
                maxCacheSize,
                grouped.format((int) Math.pow(2, maxCacheSize))
        );
    }
 
Example 4
Project: util4j   File: TestDecimalFormat.java   Source Code and License Vote up 6 votes
public static void test2(DecimalFormat df) {
	int number = 155566;
	//默认整数部分三个一组,
	System.out.println(number);//输出格式155,566
	//设置每四个一组
	df.setGroupingSize(4);
	System.out.println(df.format(number));//输出格式为15,5566
	DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance();
	//设置小数点分隔符
	dfs.setDecimalSeparator(';');
	//设置分组分隔符
	dfs.setGroupingSeparator('a');
	df.setDecimalFormatSymbols(dfs);
	System.out.println(df.format(number));//15a5566
	System.out.println(df.format(11.22));//11;22
	//取消分组
	df.setGroupingUsed(false);
	System.out.println(df.format(number));
}
 
Example 5
Project: microMathematics   File: CompatUtils.java   Source Code and License Vote up 5 votes
/**
 * Procedure creates new dot-separated DecimalFormat
 */
public static DecimalFormat getDecimalFormat(String format)
{
    DecimalFormat df = new DecimalFormat(format);
    DecimalFormatSymbols dfs = new DecimalFormatSymbols();
    dfs.setDecimalSeparator('.');
    dfs.setExponentSeparator("e");
    df.setDecimalFormatSymbols(dfs);
    return df;
}
 
Example 6
Project: jmt   File: LDStrategyEditor.java   Source Code and License Vote up 5 votes
/**
 * Helper method used to formats given number into string according to default rules.
 * @param d double to be converted
 * @return string representation of given number
 */
protected String FormatNumber(double d) {
	DecimalFormat nf = new DecimalFormat();
	nf.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.ENGLISH));
	String ret = null;
	// If module of number is greater than 1e-4 or lesser than 1e4 uses ordinary notation
	if (Math.abs(d) > 1e-4 && Math.abs(d) < 1e4 || d == 0) {
		nf.applyPattern("#.####");
		ret = nf.format(d);
	} else {
		nf.applyPattern("0.00E00");
		ret = nf.format(d);
	}
	return ret;
}
 
Example 7
Project: gdl2   File: DvQuantity.java   Source Code and License Vote up 5 votes
@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());
}
 
Example 8
Project: Ultraino   File: StringFormats.java   Source Code and License Vote up 5 votes
public StringFormats(){
    formatWith4Decs = new DecimalFormat("0.0000");
    DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols();
    otherSymbols.setDecimalSeparator('.');
    otherSymbols.setGroupingSeparator(',');
    formatWith4Decs.setDecimalFormatSymbols(otherSymbols);
    formatWith2Decs = new DecimalFormat("0.00");
    formatWith2Decs.setDecimalFormatSymbols(otherSymbols);
}
 
Example 9
Project: openjdk-jdk10   File: Helpers.java   Source Code and License Vote up 5 votes
/**
 * @return a number formatter instance which prints numbers in a human
 * readable form, like 9_223_372_036_854_775_807.
 */
public static NumberFormat numberFormatter() {
    DecimalFormat df = new DecimalFormat();
    DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();
    dfs.setGroupingSeparator('_');
    dfs.setDecimalSeparator('.');
    df.setDecimalFormatSymbols(dfs);
    return df;
}
 
Example 10
Project: java-course   File: ValueWrapper.java   Source Code and License Vote up 5 votes
/**
 * Returns parsed number.
 * @param number String number representation.
 * @return Parsed number.
 * @throws ParseException Unable to parse given string.
 */
private Number getDecimalNumber(String number) throws ParseException {
	DecimalFormat format = new DecimalFormat();
	DecimalFormatSymbols custom=new DecimalFormatSymbols();
	custom.setDecimalSeparator('.');
	format.setDecimalFormatSymbols(custom);
	return format.parse(number);
}
 
Example 11
Project: QN-ACTR-Release   File: Burst.java   Source Code and License Vote up 5 votes
/**
 * Returns this distribution's short description
 * @return distribution's short description
 */
@Override
public String toString() {
	DecimalFormat df = new DecimalFormat("#.############");
	df.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.ENGLISH));
	Double probability = (Double) parameters[0].getValue();

	//		double revProp = 1-probability.doubleValue();
	return "burst" + "(" + df.format(probability) + "," + parameters[2].getValue() + "," + parameters[4].getValue() + ")";
}
 
Example 12
Project: Ultraino   File: TransformForm.java   Source Code and License Vote up 5 votes
public static String transformToText(Transform t){
    DecimalFormat dFormat4 = new DecimalFormat("0.0000");
    DecimalFormat dFormat1 = new DecimalFormat("0.0");
    DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols();
    otherSymbols.setDecimalSeparator('.');
    otherSymbols.setGroupingSeparator(',');
    dFormat4.setDecimalFormatSymbols(otherSymbols);
    dFormat1.setDecimalFormatSymbols(otherSymbols);
    
    StringBuilder sb = new StringBuilder();
    
    Vector3f trans = t.getTranslation();
    sb.append( dFormat4.format(trans.x) ).append(" ");
    sb.append( dFormat4.format(trans.y) ).append(" ");
    sb.append( dFormat4.format(trans.z) ).append(" ");
    
    final Vector3f angles = t.getRotation().toAngles(null).multLocal( M.RAD_TO_DEG );
    sb.append(dFormat1.format( angles.x ) ).append(" ");
    sb.append(dFormat1.format( angles.y ) ).append(" ");
    sb.append(dFormat1.format( angles.z ) ).append(" ");
    
    Vector3f scale = t.getScale();
    sb.append( dFormat4.format(scale.x) ).append(" ");
    sb.append( dFormat4.format(scale.y) ).append(" ");
    sb.append( dFormat4.format(scale.z) );
    
    return sb.toString();
}
 
Example 13
Project: okwallet   File: BtcFormat.java   Source Code and License Vote up 5 votes
/** Set the currency symbol and international code of the underlying {@link
  * java.text.NumberFormat} object to the values of the last two arguments, respectively.
  * This method is invoked in the process of parsing, not formatting.
  *
  * Only invoke this from code synchronized on value of the first argument, and don't
  * forget to put the symbols back otherwise equals(), hashCode() and immutability will
  * break.  */
private static DecimalFormatSymbols setSymbolAndCode(DecimalFormat numberFormat, String symbol, String code) {
    checkState(Thread.holdsLock(numberFormat));
    DecimalFormatSymbols fs = numberFormat.getDecimalFormatSymbols();
    DecimalFormatSymbols ante = (DecimalFormatSymbols)fs.clone();
    fs.setInternationalCurrencySymbol(code);
    fs.setCurrencySymbol(symbol);
    numberFormat.setDecimalFormatSymbols(fs);
    return ante;
}
 
Example 14
Project: creacoinj   File: BtcFormat.java   Source Code and License Vote up 5 votes
/** Set the currency symbol and international code of the underlying {@link
  * java.text.NumberFormat} object to the values of the last two arguments, respectively.
  * This method is invoked in the process of parsing, not formatting.
  *
  * Only invoke this from code synchronized on value of the first argument, and don't
  * forget to put the symbols back otherwise equals(), hashCode() and immutability will
  * break.  */
private static DecimalFormatSymbols setSymbolAndCode(DecimalFormat numberFormat, String symbol, String code) {
    checkState(Thread.holdsLock(numberFormat));
    DecimalFormatSymbols fs = numberFormat.getDecimalFormatSymbols();
    DecimalFormatSymbols ante = (DecimalFormatSymbols)fs.clone();
    fs.setInternationalCurrencySymbol(code);
    fs.setCurrencySymbol(symbol);
    numberFormat.setDecimalFormatSymbols(fs);
    return ante;
}
 
Example 15
Project: morpheus-core   File: Matrix.java   Source Code and License Vote up 5 votes
/** Print the matrix to the output stream.   Line the elements up in
  * columns with a Fortran-like 'Fw.d' style format.
@param output Output stream.
@param w      Column width.
@param d      Number of digits after the decimal.
*/

public void print (PrintWriter output, int w, int d) {
   DecimalFormat format = new DecimalFormat();
   format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US));
   format.setMinimumIntegerDigits(1);
   format.setMaximumFractionDigits(d);
   format.setMinimumFractionDigits(d);
   format.setGroupingUsed(false);
   print(output,format,w+2);
}
 
Example 16
Project: intellij-randomness   File: IntegerInsertAction.java   Source Code and License Vote up 5 votes
/**
 * Returns a nicely formatted representation of a long.
 *
 * @param integer a {@code long}
 * @return a nicely formatted representation of a long
 */
private String convertToString(final long integer) {
    final DecimalFormat format = new DecimalFormat();
    format.setGroupingUsed(integerSettings.getGroupingSeparator() != '\0');

    final DecimalFormatSymbols symbols = format.getDecimalFormatSymbols();
    symbols.setGroupingSeparator(integerSettings.getGroupingSeparator());
    format.setMinimumFractionDigits(0);
    format.setMaximumFractionDigits(0);
    format.setDecimalFormatSymbols(symbols);

    return format.format(integer);
}
 
Example 17
Project: intellij-randomness   File: DecimalInsertAction.java   Source Code and License Vote up 5 votes
/**
 * Returns a nicely formatted representation of a double.
 *
 * @param decimal a {@code double}
 * @return a nicely formatted representation of a double
 */
private String convertToString(final double decimal) {
    final DecimalFormat format = new DecimalFormat();
    format.setGroupingUsed(decimalSettings.getGroupingSeparator() != '\0');

    final DecimalFormatSymbols symbols = format.getDecimalFormatSymbols();
    symbols.setGroupingSeparator(decimalSettings.getGroupingSeparator());
    symbols.setDecimalSeparator(decimalSettings.getDecimalSeparator());
    format.setMinimumFractionDigits(decimalSettings.getDecimalCount());
    format.setMaximumFractionDigits(decimalSettings.getDecimalCount());
    format.setDecimalFormatSymbols(symbols);

    return format.format(decimal);
}
 
Example 18
Project: MARF-for-Android   File: Matrix.java   Source Code and License Vote up 5 votes
/**
 * Print the matrix to the output stream.   Line the elements up in
 * columns with a Fortran-like 'Fw.d' style format.
 *
 * @param output Output stream.
 * @param w      Column width.
 * @param d      Number of digits after the decimal.
 */

public void print(PrintWriter output, int w, int d) {
    DecimalFormat format = new DecimalFormat();
    format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US));
    format.setMinimumIntegerDigits(1);
    format.setMaximumFractionDigits(d);
    format.setMinimumFractionDigits(d);
    format.setGroupingUsed(false);
    print(output, format, w + 2);
}
 
Example 19
Project: OpenJSharp   File: AbstractTranslet.java   Source Code and License Vote up 5 votes
/**
 * Adds a DecimalFormat object to the _formatSymbols hashtable.
 * The entry is created with the input DecimalFormatSymbols.
 */
public void addDecimalFormat(String name, DecimalFormatSymbols symbols) {
    // Instanciate hashtable for formatting symbols if needed
    if (_formatSymbols == null) _formatSymbols = new Hashtable();

    // The name cannot be null - use empty string instead
    if (name == null) name = EMPTYSTRING;

    // Construct a DecimalFormat object containing the symbols we got
    final DecimalFormat df = new DecimalFormat();
    if (symbols != null) {
        df.setDecimalFormatSymbols(symbols);
    }
    _formatSymbols.put(name, df);
}
 
Example 20
Project: java-course   File: ValueWrapper.java   Source Code and License Vote up 3 votes
/**
 * Returns parsed number.
 * 
 * @param number
 *            String number representation.
 * @return Parsed number.
 * @throws ParseException
 *             Unable to parse given string.
 */
private Number getDecimalNumber(String number) throws ParseException {
    DecimalFormat format = new DecimalFormat();
    DecimalFormatSymbols custom = new DecimalFormatSymbols();
    custom.setDecimalSeparator('.');
    format.setDecimalFormatSymbols(custom);
    return format.parse(number);
}