Java Code Examples for java.text.DecimalFormatSymbols#setDecimalSeparator()
The following examples show how to use
java.text.DecimalFormatSymbols#setDecimalSeparator() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CDecimalFormatter.java From Open-Lowcode with Eclipse Public License 2.0 | 6 votes |
/** * creates a decimal formatter from the server message * * @param reader reader of the message coming from the server * @throws OLcRemoteException if anything bad happens on the server * @throws IOException if a problem happens during the message * transmission */ public CDecimalFormatter(MessageReader reader) throws OLcRemoteException, IOException { reader.returnNextStartStructure("DEF"); minimum = reader.returnNextDecimalField("MIN"); maximum = reader.returnNextDecimalField("MAX"); linear = reader.returnNextBooleanField("LIN"); colorscheme = reader.returnNextBooleanField("CLS"); reader.returnNextEndStructure("DEF"); String formatfordecimalstring = "###,###.###"; formatfordecimal = new DecimalFormat(formatfordecimalstring); DecimalFormatSymbols formatforsymbol = formatfordecimal.getDecimalFormatSymbols(); formatforsymbol.setGroupingSeparator(' '); formatforsymbol.setDecimalSeparator('.'); formatfordecimal.setDecimalFormatSymbols(formatforsymbol); formatfordecimal.setParseBigDecimal(true); }
Example 2
Source File: FormatStrings.java From cuba with Apache License 2.0 | 6 votes |
public FormatStrings(char decimalSeparator, char groupingSeparator, String integerFormat, String doubleFormat, String decimalFormat, String dateFormat, String dateTimeFormat, String offsetDateTimeFormat, String timeFormat, String offsetTimeFormat, String trueString, String falseString) { formatSymbols = new DecimalFormatSymbols(); formatSymbols.setDecimalSeparator(decimalSeparator); formatSymbols.setGroupingSeparator(groupingSeparator); this.integerFormat = integerFormat; this.doubleFormat = doubleFormat; this.decimalFormat = decimalFormat; this.dateFormat = dateFormat; this.dateTimeFormat = dateTimeFormat; this.offsetDateTimeFormat = offsetDateTimeFormat; this.timeFormat = timeFormat; this.offsetTimeFormat = offsetTimeFormat; this.trueString = trueString; this.falseString = falseString; }
Example 3
Source File: AmountEditor.java From fingen with Apache License 2.0 | 6 votes |
public BigDecimal getAmount() { DecimalFormatSymbols symbols = new DecimalFormatSymbols(); symbols.setDecimalSeparator('.'); symbols.setGroupingSeparator(' '); DecimalFormat df = new DecimalFormat("#,###.##"); df.setDecimalSeparatorAlwaysShown(true); df.setDecimalFormatSymbols(symbols); df.setParseBigDecimal(true); try { String s = edAmount.getText().toString(); if (s.equals("")) { s = "0"; } return ((BigDecimal) df.parse(s.replaceAll(" ", ""))).setScale(2, RoundingMode.HALF_UP); } catch (NumberFormatException | ParseException nfe) { return BigDecimal.ZERO; } }
Example 4
Source File: PrimaveraXERFileReader.java From mpxj with GNU Lesser General Public License v2.1 | 6 votes |
/** * Process a currency definition. * * @param row record from XER file */ private void processCurrency(Row row) { String currencyName = row.getString("curr_short_name"); DecimalFormatSymbols symbols = new DecimalFormatSymbols(); symbols.setDecimalSeparator(row.getString("decimal_symbol").charAt(0)); symbols.setGroupingSeparator(row.getString("digit_group_symbol").charAt(0)); DecimalFormat nf = new DecimalFormat(); nf.setDecimalFormatSymbols(symbols); nf.applyPattern("#.#"); m_currencyMap.put(currencyName, nf); if (currencyName.equalsIgnoreCase(m_defaultCurrencyName)) { m_numberFormat = nf; m_defaultCurrencyData = row; } }
Example 5
Source File: FormatUtils.java From symbol-sdk-java with Apache License 2.0 | 6 votes |
/** * Gets a decimal format that with the desired number of decimal places. * * @param decimalPlaces The number of decimal places. * @return The desired decimal format. */ public static DecimalFormat getDecimalFormat(final int decimalPlaces) { if (decimalPlaces < 0) { throw new IllegalArgumentException("decimalPlaces must be non-negative"); } final DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(); decimalFormatSymbols.setDecimalSeparator('.'); final StringBuilder builder = new StringBuilder(); builder.append("#0"); if (decimalPlaces > 0) { builder.append('.'); final char[] zeros = new char[decimalPlaces]; Arrays.fill(zeros, '0'); builder.append(zeros); } final DecimalFormat format = new DecimalFormat(builder.toString(), decimalFormatSymbols); format.setGroupingUsed(false); return format; }
Example 6
Source File: SendingCurrencyActivity.java From guarda-android-wallets with GNU General Public License v3.0 | 6 votes |
private void updateArrivalField() { if (amountToSend == null) return; if (isInclude) { BigDecimal amountDecimal = new BigDecimal(amountToSend); BigDecimal arrivalAmountDecimal = amountDecimal.subtract(currentFeeEth); if (arrivalAmountDecimal.compareTo(BigDecimal.ZERO) < 0) { arrivalAmountDecimal = BigDecimal.ZERO; } DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(); symbols.setDecimalSeparator('.'); DecimalFormat decimalFormat = new DecimalFormat("###0.########", symbols); arrivalAmountToSend = decimalFormat.format(arrivalAmountDecimal); etArrivalAmount.setText(arrivalAmountToSend); } else { etArrivalAmount.setText(amountToSend); } }
Example 7
Source File: TransHistoryAdapter.java From guarda-android-wallets with GNU General Public License v3.0 | 6 votes |
private void retryTransaction(TransactionResponse item) { String transValue = ""; BigInteger value = new BigInteger(item.getValue()); BigDecimal decimal = new BigDecimal(value); BigDecimal formatted = new BigDecimal(WalletAPI.satoshiToCoinsString(decimal)); DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(); symbols.setDecimalSeparator('.'); DecimalFormat decimalFormat = new DecimalFormat(ETH_SHOW_PATTERN, symbols); decimalFormat.setRoundingMode(RoundingMode.DOWN); transValue = decimalFormat.format(formatted); Intent intent = new Intent(context, SendingCurrencyActivity.class); intent.putExtra(Extras.WALLET_NUMBER, item.getTo()); intent.putExtra(Extras.AMOUNT_TO_SEND, transValue); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); }
Example 8
Source File: SentenceParser.java From marine-api with GNU Lesser General Public License v3.0 | 6 votes |
/** * Set double value in specified field, with given number of digits before * and after the decimal separator ('.'). When necessary, the value is * padded with leading zeros and/or rounded to meet the requested number of * digits. * * @param index Field index * @param value Value to set * @param leading Number of digits before decimal separator * @param decimals Maximum number of digits after decimal separator * @see #setDoubleValue(int, double) */ protected final void setDoubleValue(int index, double value, int leading, int decimals) { StringBuilder pattern = new StringBuilder(); for (int i = 0; i < leading; i++) { pattern.append('0'); } if (decimals > 0) { pattern.append('.'); for (int i = 0; i < decimals; i++) { pattern.append('0'); } } if (pattern.length() == 0) { pattern.append('0'); } DecimalFormat nf = new DecimalFormat(pattern.toString()); DecimalFormatSymbols dfs = new DecimalFormatSymbols(); dfs.setDecimalSeparator('.'); nf.setDecimalFormatSymbols(dfs); setStringValue(index, nf.format(value)); }
Example 9
Source File: CompatUtils.java From microMathematics with GNU General Public License v3.0 | 5 votes |
/** * Procedure creates new dot-separated DecimalFormat */ public static DecimalFormat getDecimalFormat(String format) { DecimalFormat df = new DecimalFormat(format); DecimalFormatSymbols dfs = new DecimalFormatSymbols(); dfs.setDecimalSeparator('.'); dfs.setExponentSeparator("e"); df.setDecimalFormatSymbols(dfs); return df; }
Example 10
Source File: FortranFormat.java From ipst with Mozilla Public License 2.0 | 5 votes |
public static DecimalFormat newDF(String formatString) { DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.ENGLISH); otherSymbols.setDecimalSeparator('.'); otherSymbols.setGroupingSeparator(' '); //DecimalFormat df = new DecimalFormat("####.####",otherSymbols); DecimalFormat df = new DecimalFormat("########.########", otherSymbols); return df; }
Example 11
Source File: ExcelUtil.java From birt with Eclipse Public License 1.0 | 5 votes |
private static void updateExcelDecimalSeparator( DecimalFormat numberFormat ) { DecimalFormatSymbols symbol = numberFormat.getDecimalFormatSymbols( ); if ( symbol.getDecimalSeparator( ) != EXCEL_DECIMAL_SEPARATOR ) { symbol.setDecimalSeparator( EXCEL_DECIMAL_SEPARATOR ); numberFormat.setDecimalFormatSymbols( symbol ); } }
Example 12
Source File: AmountToSendActivity.java From guarda-android-wallets with GNU General Public License v3.0 | 5 votes |
@OnClick(R.id.btn_max) public void maxAmount(View view) { if (balance != null && !balance.equals(new BigDecimal(0))) { DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(); symbols.setDecimalSeparator('.'); symbols.setGroupingSeparator(','); DecimalFormat decimalFormat = new DecimalFormat(ETH_SHOW_PATTERN, symbols); decimalFormat.setRoundingMode(RoundingMode.FLOOR); String clearAmount = decimalFormat.format(balance).replace(",",""); etAmountToSend.setText(clearAmount); inputLayout.setCurrentText(clearAmount); etAmountToSend.setSelection(etAmountToSend.getText().length()); } }
Example 13
Source File: AmountNumberToken.java From jsr354-ri with Apache License 2.0 | 5 votes |
private void fixThousandsSeparatorWithSpace(DecimalFormatSymbols symbols) { if(Character.isSpaceChar(formatFormat.getDecimalFormatSymbols().getGroupingSeparator())){ symbols.setGroupingSeparator(' '); } if(Character.isWhitespace(formatFormat.getDecimalFormatSymbols().getDecimalSeparator())){ symbols.setDecimalSeparator(' '); } if(Character.isWhitespace(formatFormat.getDecimalFormatSymbols().getMonetaryDecimalSeparator())){ symbols.setMonetaryDecimalSeparator(' '); } }
Example 14
Source File: ScientificNotationExchangeItem.java From OpenDA with GNU Lesser General Public License v3.0 | 5 votes |
/** * Constructor * * @param id * @param description * @param role * @param value * @param format */ public ScientificNotationExchangeItem (String id, String description, Role role, double value, String format) { this.id = id; this.description = description; this.role = role; this.value = value; DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.getDefault()); otherSymbols.setDecimalSeparator('.'); this.formatter = new DecimalFormat(format, otherSymbols); }
Example 15
Source File: LocaleSafeDecimalFormat.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
/** * Regardless of the default locale, comma ('.') is used as decimal separator * * @param source * @return * @throws ParseException */ public BigDecimal parse(String source) throws ParseException { DecimalFormatSymbols symbols = new DecimalFormatSymbols(); symbols.setDecimalSeparator('.'); DecimalFormat format = new DecimalFormat("#.#", symbols); format.setParseBigDecimal(true); return (BigDecimal) format.parse(source); }
Example 16
Source File: ICalFloatFormatter.java From biweekly with BSD 2-Clause "Simplified" License | 5 votes |
/** * Creates a new formatter. * @param decimals the max number of decimal places */ public ICalFloatFormatter(int decimals) { setMaximumFractionDigits(decimals); if (decimals > 0) { setMinimumFractionDigits(1); } //decimal separator differs by locale (e.g. Germany uses ",") DecimalFormatSymbols symbols = new DecimalFormatSymbols(); symbols.setDecimalSeparator('.'); symbols.setMinusSign('-'); setDecimalFormatSymbols(symbols); }
Example 17
Source File: StandardUtil.java From Open-Lowcode with Eclipse Public License 2.0 | 5 votes |
/** * Open Lowcode uses as default a number formatting that is non ambiguous for * both English speaking and French speaking countries. Decimal separator is dot * '.', thousands grouping separator is space ' '. * * @return */ public static DecimalFormat getOLcDecimalFormatter() { String formatfordecimalstring = "###,###.###"; DecimalFormat formatfordecimal = new DecimalFormat(formatfordecimalstring); DecimalFormatSymbols formatforsymbol = formatfordecimal.getDecimalFormatSymbols(); formatforsymbol.setGroupingSeparator(' '); formatforsymbol.setDecimalSeparator('.'); formatfordecimal.setDecimalFormatSymbols(formatforsymbol); formatfordecimal.setParseBigDecimal(true); return formatfordecimal; }
Example 18
Source File: TransHistoryAdapter.java From guarda-android-wallets with GNU General Public License v3.0 | 4 votes |
@Override public void onBindViewHolder(TransHistoryItemHolder holder, final int position) { final TransactionResponse item = getTxByPosition(position); holder.rootView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (listener != null) { listener.OnItemClick(position); } } }); if (item.isError()) { // enableRetryButton(holder); holder.viewIndicator.setBackground(view.getContext().getResources().getDrawable(R.drawable.transaction_indicator_red)); holder.viewIndicator.setVisibility(View.VISIBLE); holder.tvTxStatus.setTextColor(view.getContext().getResources().getColor(R.color.txStatusRed)); holder.tvTxStatus.setText(R.string.tx_status_fail); // holder.viewIndicator.setVisibility(View.INVISIBLE); // holder.ivRetry.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // retryTransaction(item); // } // }); } else if (item.getConfirmations() == null) { // enableLoader(holder); holder.tvTxStatus.setTextColor(view.getContext().getResources().getColor(R.color.txStatusGrey)); holder.tvTxStatus.setText(R.string.tx_status_node); // holder.viewIndicator.setVisibility(View.INVISIBLE); if (repeatHandler == null || repeatHandler.isInterrupted()){ // startUpdateTask(); } } else if (Long.parseLong(item.getConfirmations()) < MIN_CONFIRMATIONS) { // starCheckTxTask(item.getHash()); // enableLoader(holder); holder.tvTxStatus.setText(R.string.tx_status_wait); // holder.viewIndicator.setVisibility(View.INVISIBLE); } else { // disableLoader(holder); holder.tvTxStatus.setVisibility(View.GONE); holder.viewIndicator.setBackground(view.getContext().getResources().getDrawable(R.drawable.transaction_indicator_green)); holder.viewIndicator.setVisibility(View.VISIBLE); } BigInteger value = new BigInteger(item.getValue()); BigDecimal decimal = new BigDecimal(value); BigDecimal formatted = new BigDecimal(WalletAPI.satoshiToCoinsString(decimal)); DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(); symbols.setDecimalSeparator('.'); DecimalFormat decimalFormat = new DecimalFormat(ETH_SHOW_PATTERN, symbols); decimalFormat.setRoundingMode(RoundingMode.DOWN); String valueStr = (isDebit(walletManager.getWalletFriendlyAddress(), item.getTo()) ? "+" : "-") + " " + decimalFormat.format(formatted); holder.tvTransactionSum.setText(valueStr); // if (isDebit(walletManager.getWalletFriendlyAddress(), item.getTo())) { // holder.viewIndicator.setBackground(view.getContext().getResources().getDrawable(R.drawable.transaction_indicator_green)); // } else { // holder.viewIndicator.setBackground(view.getContext().getResources().getDrawable(R.drawable.transaction_indicator_red)); // } holder.tvDate.setText(CalendarHelper.parseDateToddMMyyyy(item.getTimeStamp() * 1000)); }
Example 19
Source File: FgLargeValuesFormatter.java From fingen with Apache License 2.0 | 4 votes |
public FgLargeValuesFormatter() { DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.getDefault()); otherSymbols.setDecimalSeparator('.'); otherSymbols.setGroupingSeparator(Character.MIN_VALUE); mFormat = new DecimalFormat("###E0", otherSymbols); }
Example 20
Source File: JdbcResultSet.java From ignite with Apache License 2.0 | 3 votes |
/** {@inheritDoc} */ @Override protected DecimalFormat initialValue() { DecimalFormatSymbols symbols = new DecimalFormatSymbols(); symbols.setGroupingSeparator(','); symbols.setDecimalSeparator('.'); String ptrn = "#,##0.0#"; DecimalFormat decimalFormat = new DecimalFormat(ptrn, symbols); decimalFormat.setParseBigDecimal(true); return decimalFormat; }