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