本文整理汇总了Java中java.text.DecimalFormatSymbols.setNaN方法的典型用法代码示例。如果您正苦于以下问题:Java DecimalFormatSymbols.setNaN方法的具体用法?Java DecimalFormatSymbols.setNaN怎么用?Java DecimalFormatSymbols.setNaN使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.text.DecimalFormatSymbols
的用法示例。
在下文中一共展示了DecimalFormatSymbols.setNaN方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: castToString
import java.text.DecimalFormatSymbols; //导入方法依赖的package包/类
public static String castToString(double d)
{
double dAbs = Math.abs(d);
DecimalFormatSymbols decfmtsymb = new DecimalFormatSymbols(java.util.Locale.US); // US locale represents numbers with a . as comma and without any (ten)thousend separators.
decfmtsymb.setInfinity("INF");
decfmtsymb.setNaN("NaN");
DecimalFormat decfmt = new DecimalFormat((dAbs > 1E7 || dAbs < 1E-3) && dAbs > 0.0 ?
"0.##############E000" : "0.#############", decfmtsymb);
String s = decfmt.format(d);
// 1.234E567 => 1.234E+567
int e = s.indexOf("E");
if (e > 0 && s.charAt(e+1) != '-' )
s = s.substring(0, e) + "E+" + s.substring(e+1);
return s;
}
示例2: initialValue
import java.text.DecimalFormatSymbols; //导入方法依赖的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;
}