本文整理匯總了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;
}