本文整理汇总了Java中java.text.NumberFormat.getInstance方法的典型用法代码示例。如果您正苦于以下问题:Java NumberFormat.getInstance方法的具体用法?Java NumberFormat.getInstance怎么用?Java NumberFormat.getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.text.NumberFormat
的用法示例。
在下文中一共展示了NumberFormat.getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDecimalFormat
import java.text.NumberFormat; //导入方法依赖的package包/类
/**
* Make an instance of DecimalFormat.
*
* @param locale The locale
* @param pattern The pattern is used for the convertion
* @return The format for the locale and pattern
*
* @throws ConversionException if conversion cannot be performed
* successfully
* @throws ParseException if an error occurs parsing a String to a Number
*/
private DecimalFormat getDecimalFormat(final Locale locale, final String pattern) {
final DecimalFormat numberFormat = (DecimalFormat) NumberFormat.getInstance(locale);
// if some constructors default pattern to null, it makes only sense to handle null pattern gracefully
if (pattern != null) {
if (locPattern) {
numberFormat.applyLocalizedPattern(pattern);
} else {
numberFormat.applyPattern(pattern);
}
} else {
log.debug("No pattern provided, using default.");
}
return numberFormat;
}
示例2: setZoomHistoryNext
import java.text.NumberFormat; //导入方法依赖的package包/类
public void setZoomHistoryNext(XMap mapSource) {
Rectangle2D r = null;
r = mapSource.getClipRect2D();
Point2D.Double p2 = new Point2D.Double(
r.getX()+.5*r.getWidth(),
r.getY()+.5*r.getHeight() );
p2 = (Point2D.Double)mapSource.getProjection().getRefXY(p2);
double zoom = mapSource.getZoom();
NumberFormat fmtZoom1 = NumberFormat.getInstance();
fmtZoom1.setMinimumFractionDigits(1);
fmtZoom1.format(zoom);
nextZoom = "next, " + p2.getX() + ", " + p2.getY() + ", " + zoom;
zoomActionTrack.selectAll();
zoomActionTrack.replaceSelection(nextZoom);
//System.out.println("track: " + zoomActionTrack.getText());
}
示例3: getLocalisedDouble
import java.text.NumberFormat; //导入方法依赖的package包/类
/**
* Convert a string back into a Float. Assumes string was formatted using formatLocalisedNumber originally. Should
* ensure that it is using the same locale/number format as when it was formatted. If no locale is suppied, it will
* use the server's locale.
*
* Need to strip out any spaces as spaces are valid group separators in some European locales (e.g. Polish) but they
* seem to come back from Firefox as a plain space rather than the special separating space.
*/
public static Double getLocalisedDouble(String inputStr, Locale locale) {
String numberStr = inputStr;
if (numberStr != null) {
numberStr = numberStr.replace(" ", "");
}
if ((numberStr != null) && (numberStr.length() > 0)) {
Locale useLocale = locale != null ? locale : NumberUtil.getServerLocale();
NumberFormat format = NumberFormat.getInstance(useLocale);
ParsePosition pp = new ParsePosition(0);
Number num = format.parse(numberStr, pp);
if ((num != null) && (pp.getIndex() == numberStr.length())) {
return num.doubleValue();
}
}
throw new NumberFormatException("Unable to convert number " + numberStr + "to double using locale "
+ locale.getCountry() + " " + locale.getLanguage());
}
示例4: getSuccessPercentageForSuite
import java.text.NumberFormat; //导入方法依赖的package包/类
public String getSuccessPercentageForSuite()
{
String successPercentageForSuite = "";
NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(2);
nf.setGroupingUsed(true);
try
{
successPercentageForSuite = nf
.format(((float) getTotalPassedMethodsForSuite() / (float) (getTotalPassedMethodsForSuite()
+ getTotalFailedMethodsForSuite() + getTotalSkippedMethodsForSuite())) * 100);
} catch (NumberFormatException realCause)
{
LOGGER.debug(realCause.getMessage());
}
return successPercentageForSuite;
}
示例5: updateTotalDistance
import java.text.NumberFormat; //导入方法依赖的package包/类
@Override
public void updateTotalDistance(Context context) {
if(context != null){
SharedPreferences sp = context.getSharedPreferences(RMConfiguration.FILE_CONFIG, Context.MODE_PRIVATE);
long distance = sp.getLong(RMConfiguration.KEY_TOTAL_DISTANCE,0);
long tmpDistance = sp.getLong(RMConfiguration.KEY_TMP_DISTANCE,0);
if(tmpDistance < 0){
return;
}
distance += tmpDistance;
//if there have an effective value, update it now
SharedPreferences.Editor editor = sp.edit();
editor.putLong(RMConfiguration.KEY_TMP_DISTANCE,0);
editor.putLong(RMConfiguration.KEY_TOTAL_DISTANCE,distance);
editor.commit();
DecimalFormat distanceFormater = (DecimalFormat) NumberFormat.getInstance();
distanceFormater.setMinimumFractionDigits(2);
distanceFormater.setMaximumFractionDigits(2);
mFunctionFragment.showUpgradeDistance(distanceFormater.format(distance/1000.0));
}
}
示例6: num2decStr
import java.text.NumberFormat; //导入方法依赖的package包/类
public static String num2decStr(double num, int digits) {
NumberFormat nf = NumberFormat.getInstance(Locale.ENGLISH);
nf.setMinimumFractionDigits(digits);
nf.setMaximumFractionDigits(digits);
String result = nf.format(num);
return result;
}
示例7: handleResult
import java.text.NumberFormat; //导入方法依赖的package包/类
public void handleResult(Codec codec, Result result) {
if (result.getError() != null) {
result.getError().printStackTrace();
return;
}
NumberFormat format = NumberFormat.getInstance();
System.out.println(result.getName() + "\t" + codec.getName() + "\t" + format.format(result.getMillis()) + "\tYGC " + result.getYoungGC()
+ "\tYGCT " + result.getYoungGCTime());
}
示例8: getText
import java.text.NumberFormat; //导入方法依赖的package包/类
@Override
public String getText()
{
final NumberFormat numberFormat = NumberFormat.getInstance(CurrentLocale.getLocale());
if( minDecimals != null )
{
numberFormat.setMinimumFractionDigits(minDecimals);
}
if( maxDecimals != null )
{
numberFormat.setMaximumFractionDigits(maxDecimals);
}
return numberFormat.format(number);
}
示例9: testLocalizationValues
import java.text.NumberFormat; //导入方法依赖的package包/类
private static int testLocalizationValues() {
DecimalFormat df = (DecimalFormat)
NumberFormat.getInstance(GoldenDoubleValues.FullLocalizationTestLocale);
double[] localizationValues = GoldenDoubleValues.DecimalLocalizationValues;
int size = localizationValues.length;
int successCounter = 0;
int failureCounter = 0;
for (int i = 0; i < size; i++) {
double d = localizationValues[i];
String formatted = df.format(d);
char[] expectedUnicodeArray =
getCharsFromUnicodeArray(
GoldenFormattedValues.DecimalDigitsLocalizedFormattedValues[i]);
String expected = new String(expectedUnicodeArray);
if (!formatted.equals(expected)) {
failureCounter++;
System.out.println(
"--- Localization error for value d = " + d +
". Exact value = " + new BigDecimal(d).toString() +
". Expected result = " + expected +
". Output result = " + formatted);
} else successCounter++;
}
System.out.println("Checked positively " + successCounter +
" golden decimal values out of " + size +
" tests. There were " + failureCounter +
" format failure");
return failureCounter;
}
示例10: parseFee
import java.text.NumberFormat; //导入方法依赖的package包/类
private static float parseFee(String managementFee) throws ComparisonException, ParseException {
float fee;
if (managementFee.contains(",")){
NumberFormat format = NumberFormat.getInstance(Locale.FRANCE);
Number number = format.parse(managementFee);
fee = number.floatValue()/100;
}
else {
fee = Float.parseFloat(managementFee)/100;
}
if (fee > 0.02 || fee < 0) throw new FeeSizeException("Fee size does not match Estonian standards");
return fee;
}
示例11: XMLConsumer
import java.text.NumberFormat; //导入方法依赖的package包/类
public XMLConsumer(File fileName) throws IOException
{
writer = new OutputStreamWriter(new FileOutputStream(fileName), "UTF-8");
addAutoclose(this);
writer.write("<benchmark-results tstamp=\"" + tstamp() + "\">\n\n");
nf = NumberFormat.getInstance(Locale.ENGLISH);
nf.setMaximumFractionDigits(3);
nf.setGroupingUsed(false);
}
示例12: TvshowDetailedPresenter
import java.text.NumberFormat; //导入方法依赖的package包/类
public TvshowDetailedPresenter(Context context, ExtendedClickListener listener) {
super(context, AdapterDefaultValuesDetails.INSTANCE, listener);
mNumberFormat = NumberFormat.getInstance();
mNumberFormat.setMinimumFractionDigits(1);
mNumberFormat.setMaximumFractionDigits(1);
mDateFormat = DateFormat.getDateInstance(DateFormat.LONG);
}
示例13: TvshowListPresenter
import java.text.NumberFormat; //导入方法依赖的package包/类
public TvshowListPresenter(Context context, AdapterDefaultValues defaultValues,ExtendedClickListener listener) {
super(context, defaultValues, listener);
mNumberFormat = NumberFormat.getInstance();
mNumberFormat.setMinimumFractionDigits(1);
mNumberFormat.setMaximumFractionDigits(1);
mDateFormat = DateFormat.getDateInstance(DateFormat.LONG);
}
示例14: getMeasuresRow
import java.text.NumberFormat; //导入方法依赖的package包/类
public List<String> getMeasuresRow(Object[] measures, String title) {
List<AnnotationDiffer> differs = new ArrayList<AnnotationDiffer>(
getDifferByTypeMap().values());
AnnotationDiffer differ = new AnnotationDiffer(differs);
NumberFormat f = NumberFormat.getInstance(Locale.ENGLISH);
f.setMaximumFractionDigits(2);
f.setMinimumFractionDigits(2);
List<String> row = new ArrayList<String>();
row.add(title);
row.add(Integer.toString(differ.getCorrectMatches()));
row.add(Integer.toString(differ.getMissing()));
row.add(Integer.toString(differ.getSpurious()));
row.add(Integer.toString(differ.getPartiallyCorrectMatches()));
for (Object object : measures) {
String measure = (String) object;
double beta = Double.valueOf(
measure.substring(1,measure.indexOf('-')));
if (measure.endsWith("strict")) {
row.add(f.format(differ.getPrecisionStrict()));
row.add(f.format(differ.getRecallStrict()));
row.add(f.format(differ.getFMeasureStrict(beta)));
} else if (measure.endsWith("strict BDM")) {
row.add(f.format(getPrecisionStrictBdm()));
row.add(f.format(getRecallStrictBdm()));
row.add(f.format(getFMeasureStrictBdm(beta)));
} else if (measure.endsWith("lenient")) {
row.add(f.format(differ.getPrecisionLenient()));
row.add(f.format(differ.getRecallLenient()));
row.add(f.format(differ.getFMeasureLenient(beta)));
} else if (measure.endsWith("lenient BDM")) {
row.add(f.format(getPrecisionLenientBdm()));
row.add(f.format(getRecallLenientBdm()));
row.add(f.format(getFMeasureLenientBdm(beta)));
} else if (measure.endsWith("average")) {
row.add(f.format(differ.getPrecisionAverage()));
row.add(f.format(differ.getRecallAverage()));
row.add(f.format(differ.getFMeasureAverage(beta)));
} else if (measure.endsWith("average BDM")) {
row.add(f.format(getPrecisionAverageBdm()));
row.add(f.format(getRecallAverageBdm()));
row.add(f.format(getFMeasureAverageBdm(beta)));
}
}
return row;
}
示例15: determineDecimalSeparator
import java.text.NumberFormat; //导入方法依赖的package包/类
public void determineDecimalSeparator() {
NumberFormat numberFormat = NumberFormat.getInstance();
if (numberFormat instanceof DecimalFormat) {
decimalSeparator = ((DecimalFormat) numberFormat).getDecimalFormatSymbols().getDecimalSeparator();
}
}