本文整理汇总了Java中java.text.DecimalFormatSymbols.getInstance方法的典型用法代码示例。如果您正苦于以下问题:Java DecimalFormatSymbols.getInstance方法的具体用法?Java DecimalFormatSymbols.getInstance怎么用?Java DecimalFormatSymbols.getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.text.DecimalFormatSymbols
的用法示例。
在下文中一共展示了DecimalFormatSymbols.getInstance方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInstance
import java.text.DecimalFormatSymbols; //导入方法依赖的package包/类
private NumberFormat getInstance(Locale locale,
int choice) {
if (locale == null) {
throw new NullPointerException();
}
LocaleProviderAdapter adapter = LocaleProviderAdapter.forType(type);
String[] numberPatterns = adapter.getLocaleResources(locale).getNumberPatterns();
DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locale);
int entry = (choice == INTEGERSTYLE) ? NUMBERSTYLE : choice;
DecimalFormat format = new DecimalFormat(numberPatterns[entry], symbols);
if (choice == INTEGERSTYLE) {
format.setMaximumFractionDigits(0);
format.setDecimalSeparatorAlwaysShown(false);
format.setParseIntegerOnly(true);
} else if (choice == CURRENCYSTYLE) {
adjustForCurrencyDefaultFractionDigits(format, symbols);
}
return format;
}
示例2: test2
import java.text.DecimalFormatSymbols; //导入方法依赖的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));
}
示例3: placeOrder
import java.text.DecimalFormatSymbols; //导入方法依赖的package包/类
/**
* Purchase something
*
* @param currencyMarketId the market on which to purchase
* @param amount the amount to buy
* @param ppc the price expected
* @param category trade-kind purchase or sale
* @return the order confirmation
*/
public OrderData placeOrder(long currencyMarketId, double amount, double ppc, PurchaseCategory category) throws HashnestServiceException {
NumberFormat nmbrFmt = new DecimalFormat("0.########", DecimalFormatSymbols.getInstance(Locale.US));
Map<String, String> signature = keyGen.signature();
signature.put("currency_market_id", String.valueOf(currencyMarketId));
signature.put("amount", nmbrFmt.format(amount));
signature.put("ppc", nmbrFmt.format(ppc));
signature.put("category", category.code);
ResponseEntity<String> response = callHashnestWithRetry(signature, String.class, API_GET_ORDERS_EXECUTE, "execute order");
if (response == null) return null;
OrderData orderData = null;
if (response.getBody() != null && response.getStatusCodeValue() == 201) {
log.debug("received order execution body as response: {}", response.getBody());
ObjectMapper mapper = new ObjectMapper();
try {
orderData = mapper.readValue(response.getBody(), OrderData.class);
log.debug("OrderData received, order has been placed {}", orderData);
} catch (Exception e) {
throw new HashnestServiceException(format("order failed to execute %s", response.getBody()));
}
}
return orderData;
}
示例4: formatSeconds
import java.text.DecimalFormatSymbols; //导入方法依赖的package包/类
/**
* Formats seconds
* @param seconds the number of seconds to format
* @return a string formatted with a different unit depending on the number of seconds
*/
private String formatSeconds(int seconds) {
String time;
DecimalFormat decimal = new DecimalFormat("0.0", DecimalFormatSymbols.getInstance(Locale.getDefault()));
DecimalFormat integer = new DecimalFormat("0");
float min = seconds / 60.0f;
float hour = min / 60.0f;
if(hour > 1) {
time = hasDecimal(hour) ? decimal.format(hour).concat(" h") : integer.format(hour).concat(" h");
} else if(min > 1) {
time = hasDecimal(min) ? decimal.format(min).concat(" m") : integer.format(min).concat(" m");
} else {
time = integer.format(seconds).concat(" s");
}
return time;
}
示例5: format
import java.text.DecimalFormatSymbols; //导入方法依赖的package包/类
public static String format(long amountValue, int exponent, Locale locale) {
String valueString;
if (exponent > 0) {
final String sign = (amountValue < 0) ? "-" : "";
long absAmountValue = Math.abs(amountValue);
long power = 1;
for (int i = 0; i < exponent; i++) {
power *= 10;
}
if (locale != null) {
DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(locale);
String highValue = NumberFormat.getInstance(locale).format((absAmountValue / power));
valueString = String.format("%s%s%s%0" + exponent + "d", sign, highValue, dfs.getDecimalSeparator(),
(absAmountValue % power));
} else {
valueString = String.format("%s%d.%0" + exponent + "d", sign, (absAmountValue / power),
(absAmountValue % power));
}
} else {
if (locale != null) {
valueString = NumberFormat.getInstance(locale).format(amountValue);
} else {
valueString = String.valueOf(amountValue);
}
}
return valueString;
}
示例6: prettyPrint
import java.text.DecimalFormatSymbols; //导入方法依赖的package包/类
/**
* Pretty prints a double value (with maximal necessary precision or as integer, if so).
*
* @param value
* @return
*/
public static String prettyPrint(double value) {
/*
To remove - sign if value is zero
*/
if (Double.compare(-0d, value) == 0) {
value *= -1d;
}
/*
Solution by: http://stackoverflow.com/a/25308216
*/
DecimalFormat df = new DecimalFormat("0", DecimalFormatSymbols.getInstance(Locale.ENGLISH));
df.setMaximumFractionDigits(340); //340 = DecimalFormat.DOUBLE_FRACTION_DIGITS
return df.format(value);
}
示例7: getSearchSpaceScientific
import java.text.DecimalFormatSymbols; //导入方法依赖的package包/类
/**
* @return the approximate solution space as a string formatted in
* scientific notation
*/
public String getSearchSpaceScientific() {
BigInteger solSpace = getSearchSpace();
String solSpaceScientific = solSpace.toString();
if (solSpace.compareTo(BigInteger.valueOf(100000)) > 0) {
NumberFormat formatter = new DecimalFormat("0.######E0", DecimalFormatSymbols.getInstance(Locale.ROOT));
solSpaceScientific = formatter.format(solSpace);
}
return solSpaceScientific;
}
示例8: initSettings
import java.text.DecimalFormatSymbols; //导入方法依赖的package包/类
/***
* If user does not provide a valid locale it throws IllegalArgumentException.
*
* If throws an IllegalArgumentException the locale sets to default locale
*/
private void initSettings() {
boolean success = false;
while (!success) {
try {
fractionDigit = Currency.getInstance(locale).getDefaultFractionDigits();
DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locale);
if (mGroupDivider > 0)
symbols.setGroupingSeparator(mGroupDivider);
groupDivider = symbols.getGroupingSeparator();
if (mMonetaryDivider > 0)
symbols.setMonetaryDecimalSeparator(mMonetaryDivider);
monetaryDivider = symbols.getMonetaryDecimalSeparator();
currencySymbol = symbols.getCurrencySymbol();
DecimalFormat df = (DecimalFormat) DecimalFormat.getCurrencyInstance(locale);
numberFormat = new DecimalFormat(df.toPattern(), symbols);
success = true;
} catch (IllegalArgumentException e) {
Log.e(getClass().getCanonicalName(), e.getMessage());
locale = getDefaultLocale();
}
}
}
示例9: formatValue
import java.text.DecimalFormatSymbols; //导入方法依赖的package包/类
@Override
public String formatValue(String key, Object value) {
if (key.equals(Command.KEY_TIMEZONE)) {
double offset = TimeZone.getTimeZone((String) value).getRawOffset() / 3600000.0;
DecimalFormat fmt = new DecimalFormat("+#.##;-#.##", DecimalFormatSymbols.getInstance(Locale.US));
return fmt.format(offset);
}
return null;
}
示例10: create
import java.text.DecimalFormatSymbols; //导入方法依赖的package包/类
private static DecimalStyle create(Locale locale) {
DecimalFormatSymbols oldSymbols = DecimalFormatSymbols.getInstance(locale);
char zeroDigit = oldSymbols.getZeroDigit();
char positiveSign = '+';
char negativeSign = oldSymbols.getMinusSign();
char decimalSeparator = oldSymbols.getDecimalSeparator();
if (zeroDigit == '0' && negativeSign == '-' && decimalSeparator == '.') {
return STANDARD;
}
return new DecimalStyle(zeroDigit, positiveSign, negativeSign, decimalSeparator);
}
示例11: getZero
import java.text.DecimalFormatSymbols; //导入方法依赖的package包/类
private static char getZero(Locale l) {
if ((l != null) && !l.equals(Locale.US)) {
DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(l);
return dfs.getZeroDigit();
} else {
return '0';
}
}
示例12: HashnestUtils
import java.text.DecimalFormatSymbols; //导入方法依赖的package包/类
public HashnestUtils() {
formatBtcNmbr = new DecimalFormat("0.00000000", DecimalFormatSymbols.getInstance(Locale.US));
formatSatNmbr = new DecimalFormat("#,###.##", DecimalFormatSymbols.getInstance(Locale.US));
}
示例13: checkDigit
import java.text.DecimalFormatSymbols; //导入方法依赖的package包/类
private void checkDigit(Locale loc, Character expected) {
DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(loc);
Character zero = dfs.getZeroDigit();
assertEquals("Wrong digit zero char", expected, zero);
}