本文整理汇总了Java中java.text.DecimalFormat.setDecimalFormatSymbols方法的典型用法代码示例。如果您正苦于以下问题:Java DecimalFormat.setDecimalFormatSymbols方法的具体用法?Java DecimalFormat.setDecimalFormatSymbols怎么用?Java DecimalFormat.setDecimalFormatSymbols使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.text.DecimalFormat
的用法示例。
在下文中一共展示了DecimalFormat.setDecimalFormatSymbols方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initialValue
import java.text.DecimalFormat; //导入方法依赖的package包/类
@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;
}
示例2: cluster_simplfication
import java.text.DecimalFormat; //导入方法依赖的package包/类
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;
}
示例3: printTestInfo
import java.text.DecimalFormat; //导入方法依赖的package包/类
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))
);
}
示例4: test2
import java.text.DecimalFormat; //导入方法依赖的package包/类
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));
}
示例5: getDecimalFormat
import java.text.DecimalFormat; //导入方法依赖的package包/类
/**
* 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;
}
示例6: FormatNumber
import java.text.DecimalFormat; //导入方法依赖的package包/类
/**
* 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;
}
示例7: toString
import java.text.DecimalFormat; //导入方法依赖的package包/类
@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());
}
示例8: StringFormats
import java.text.DecimalFormat; //导入方法依赖的package包/类
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);
}
示例9: numberFormatter
import java.text.DecimalFormat; //导入方法依赖的package包/类
/**
* @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;
}
示例10: getDecimalNumber
import java.text.DecimalFormat; //导入方法依赖的package包/类
/**
* 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);
}
示例11: toString
import java.text.DecimalFormat; //导入方法依赖的package包/类
/**
* 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() + ")";
}
示例12: transformToText
import java.text.DecimalFormat; //导入方法依赖的package包/类
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();
}
示例13: setSymbolAndCode
import java.text.DecimalFormat; //导入方法依赖的package包/类
/** 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;
}
示例14: print
import java.text.DecimalFormat; //导入方法依赖的package包/类
/** 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);
}
示例15: convertToString
import java.text.DecimalFormat; //导入方法依赖的package包/类
/**
* 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);
}