Java Code Examples for java.text.DecimalFormat#setRoundingMode()
The following examples show how to use
java.text.DecimalFormat#setRoundingMode() .
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: 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().substring(2)); BigDecimal decimal = new BigDecimal(value); BigDecimal formatted = Convert.fromWei(decimal, Convert.Unit.ETHER); 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 2
Source File: DoubleConversor.java From nfse with MIT License | 5 votes |
public String toString(Object obj){ DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.ROOT); symbols.setDecimalSeparator('.'); symbols.setGroupingSeparator(','); DecimalFormat formatDecimal = new DecimalFormat("#0.00", symbols); formatDecimal.setRoundingMode(RoundingMode.HALF_UP); return formatDecimal.format((Double) obj); }
Example 3
Source File: FormatUtil.java From ClockView with Apache License 2.0 | 5 votes |
public static String float2Str(float value, String format, RoundingMode mode) { DecimalFormat decimalFormat = getDecimal(format); if (mode != null) { decimalFormat.setRoundingMode(mode); } return decimalFormat.format(value); }
Example 4
Source File: TransactionDetailsActivity.java From guarda-android-wallets with GNU General Public License v3.0 | 5 votes |
private String balanceToString(BigDecimal balance) { DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(); symbols.setDecimalSeparator('.'); DecimalFormat decimalFormat = new DecimalFormat(ETH_SHOW_PATTERN, symbols); decimalFormat.setRoundingMode(RoundingMode.DOWN); if (!balance.equals(new BigDecimal(0))) { return decimalFormat.format(balance); } else { return "00.00"; } }
Example 5
Source File: SellConfirmCoinifyActivity.java From guarda-android-wallets with GNU General Public License v3.0 | 5 votes |
@Override protected void init(Bundle savedInstanceState) { GuardaApp.getAppComponent().inject(this); setToolBarTitle(getString(R.string.toolbar_title_confirm_coinify)); baseAmount = getIntent().getFloatExtra(Extras.COINIFY_IN_AMOUNT, 0.0f); float amountWithCoinifyFee = 0.0f; payMethod = getIntent().getStringExtra(Extras.COINIFY_PAY_METHOD); fee.setText(String.format("%s %s" , getIntent().getStringExtra(Extras.COINIFY_EXCH_FEE), getIntent().getStringExtra(Extras.COINIFY_OUT_AMOUNT_CUR))); til_coinify_method_fee.setHint(String.format("%s Order", getIntent().getStringExtra(Extras.COINIFY_OUT_AMOUNT_CUR))); txfee.setText(String.format("%s %s", getIntent().getStringExtra(Extras.COINIFY_COINIFY_FEE), getIntent().getStringExtra(Extras.COINIFY_OUT_AMOUNT_CUR))); coinify_method_fee.setText(String.format("%s %s", getIntent().getStringExtra(Extras.COINIFY_AMOUNT_RATE), getIntent().getStringExtra(Extras.COINIFY_OUT_AMOUNT_CUR))); coinify_bank_chb_text.setText(R.string.coinify_sell_confirm); btnNext.setEnabled(false); DecimalFormat df = new DecimalFormat("#.##"); df.setRoundingMode(RoundingMode.HALF_EVEN); send.setText(String.format("%s %s", getIntent().getFloatExtra(Extras.COINIFY_IN_AMOUNT, 0.0f), getIntent().getStringExtra(Extras.COINIFY_IN_AMOUNT_CUR))); String tvapx = getIntent().getStringExtra(Extras.COINIFY_OUT_AMOUNT); received.setText(String.format("%s %s", tvapx, getIntent().getStringExtra(Extras.COINIFY_OUT_AMOUNT_CUR))); email.setText(sharedManager.getCoinifyEmail()); coinify_bank_chb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { btnNext.setEnabled(true); } else { btnNext.setEnabled(false); } } }); }
Example 6
Source File: AmountToSendActivity.java From guarda-android-wallets with GNU General Public License v3.0 | 5 votes |
private void updateTokenBalance(){ balance = tokenManager.getTokenByCode(tokenCode).getTokenNum(); DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(); symbols.setDecimalSeparator('.'); symbols.setGroupingSeparator(','); DecimalFormat decimalFormat = new DecimalFormat(ETH_SHOW_PATTERN, symbols); decimalFormat.setRoundingMode(RoundingMode.DOWN); if (balance != null && !balance.equals(new BigDecimal(0))) { setCurrentBalance(decimalFormat.format(balance), tokenCode.toUpperCase()); } }
Example 7
Source File: SellConfirmCoinifyActivity.java From guarda-android-wallets with GNU General Public License v3.0 | 5 votes |
@Override protected void init(Bundle savedInstanceState) { GuardaApp.getAppComponent().inject(this); setToolBarTitle(getString(R.string.toolbar_title_confirm_coinify)); baseAmount = getIntent().getFloatExtra(Extras.COINIFY_IN_AMOUNT, 0.0f); float amountWithCoinifyFee = 0.0f; payMethod = getIntent().getStringExtra(Extras.COINIFY_PAY_METHOD); fee.setText(String.format("%s %s" , getIntent().getStringExtra(Extras.COINIFY_EXCH_FEE), getIntent().getStringExtra(Extras.COINIFY_OUT_AMOUNT_CUR))); til_coinify_method_fee.setHint(String.format("%s Order", getIntent().getStringExtra(Extras.COINIFY_OUT_AMOUNT_CUR))); txfee.setText(String.format("%s %s", getIntent().getStringExtra(Extras.COINIFY_COINIFY_FEE), getIntent().getStringExtra(Extras.COINIFY_OUT_AMOUNT_CUR))); coinify_method_fee.setText(String.format("%s %s", getIntent().getStringExtra(Extras.COINIFY_AMOUNT_RATE), getIntent().getStringExtra(Extras.COINIFY_OUT_AMOUNT_CUR))); coinify_bank_chb_text.setText(R.string.coinify_sell_confirm); btnNext.setEnabled(false); DecimalFormat df = new DecimalFormat("#.##"); df.setRoundingMode(RoundingMode.HALF_EVEN); send.setText(String.format("%s %s", getIntent().getFloatExtra(Extras.COINIFY_IN_AMOUNT, 0.0f), getIntent().getStringExtra(Extras.COINIFY_IN_AMOUNT_CUR))); String tvapx = getIntent().getStringExtra(Extras.COINIFY_OUT_AMOUNT); received.setText(String.format("%s %s", tvapx, getIntent().getStringExtra(Extras.COINIFY_OUT_AMOUNT_CUR))); email.setText(sharedManager.getCoinifyEmail()); coinify_bank_chb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { btnNext.setEnabled(true); } else { btnNext.setEnabled(false); } } }); }
Example 8
Source File: SellConfirmCoinifyActivity.java From guarda-android-wallets with GNU General Public License v3.0 | 5 votes |
@Override protected void init(Bundle savedInstanceState) { GuardaApp.getAppComponent().inject(this); setToolBarTitle(getString(R.string.toolbar_title_confirm_coinify)); baseAmount = getIntent().getFloatExtra(Extras.COINIFY_IN_AMOUNT, 0.0f); float amountWithCoinifyFee = 0.0f; payMethod = getIntent().getStringExtra(Extras.COINIFY_PAY_METHOD); fee.setText(String.format("%s %s" , getIntent().getStringExtra(Extras.COINIFY_EXCH_FEE), getIntent().getStringExtra(Extras.COINIFY_OUT_AMOUNT_CUR))); til_coinify_method_fee.setHint(String.format("%s Order", getIntent().getStringExtra(Extras.COINIFY_OUT_AMOUNT_CUR))); txfee.setText(String.format("%s %s", getIntent().getStringExtra(Extras.COINIFY_COINIFY_FEE), getIntent().getStringExtra(Extras.COINIFY_OUT_AMOUNT_CUR))); coinify_method_fee.setText(String.format("%s %s", getIntent().getStringExtra(Extras.COINIFY_AMOUNT_RATE), getIntent().getStringExtra(Extras.COINIFY_OUT_AMOUNT_CUR))); coinify_bank_chb_text.setText(R.string.coinify_sell_confirm); btnNext.setEnabled(false); DecimalFormat df = new DecimalFormat("#.##"); df.setRoundingMode(RoundingMode.HALF_EVEN); send.setText(String.format("%s %s", getIntent().getFloatExtra(Extras.COINIFY_IN_AMOUNT, 0.0f), getIntent().getStringExtra(Extras.COINIFY_IN_AMOUNT_CUR))); String tvapx = getIntent().getStringExtra(Extras.COINIFY_OUT_AMOUNT); received.setText(String.format("%s %s", tvapx, getIntent().getStringExtra(Extras.COINIFY_OUT_AMOUNT_CUR))); email.setText(sharedManager.getCoinifyEmail()); coinify_bank_chb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { btnNext.setEnabled(true); } else { btnNext.setEnabled(false); } } }); }
Example 9
Source File: StringFormatting.java From thunderstorm with GNU General Public License v3.0 | 5 votes |
public static DecimalFormat getDecimalFormat(int floatPrecision) { DecimalFormat df = new DecimalFormat(); DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(Locale.US); symbols.setInfinity("Infinity"); symbols.setNaN("NaN"); df.setDecimalFormatSymbols(symbols); df.setGroupingUsed(false); df.setRoundingMode(RoundingMode.HALF_EVEN); df.setMaximumFractionDigits(floatPrecision); return df; }
Example 10
Source File: SellConfirmCoinifyActivity.java From guarda-android-wallets with GNU General Public License v3.0 | 5 votes |
@Override protected void init(Bundle savedInstanceState) { GuardaApp.getAppComponent().inject(this); setToolBarTitle(getString(R.string.toolbar_title_confirm_coinify)); baseAmount = getIntent().getFloatExtra(Extras.COINIFY_IN_AMOUNT, 0.0f); float amountWithCoinifyFee = 0.0f; payMethod = getIntent().getStringExtra(Extras.COINIFY_PAY_METHOD); fee.setText(String.format("%s %s" , getIntent().getStringExtra(Extras.COINIFY_EXCH_FEE), getIntent().getStringExtra(Extras.COINIFY_OUT_AMOUNT_CUR))); til_coinify_method_fee.setHint(String.format("%s Order", getIntent().getStringExtra(Extras.COINIFY_OUT_AMOUNT_CUR))); txfee.setText(String.format("%s %s", getIntent().getStringExtra(Extras.COINIFY_COINIFY_FEE), getIntent().getStringExtra(Extras.COINIFY_OUT_AMOUNT_CUR))); coinify_method_fee.setText(String.format("%s %s", getIntent().getStringExtra(Extras.COINIFY_AMOUNT_RATE), getIntent().getStringExtra(Extras.COINIFY_OUT_AMOUNT_CUR))); coinify_bank_chb_text.setText(R.string.coinify_sell_confirm); btnNext.setEnabled(false); DecimalFormat df = new DecimalFormat("#.##"); df.setRoundingMode(RoundingMode.HALF_EVEN); send.setText(String.format("%s %s", getIntent().getFloatExtra(Extras.COINIFY_IN_AMOUNT, 0.0f), getIntent().getStringExtra(Extras.COINIFY_IN_AMOUNT_CUR))); String tvapx = getIntent().getStringExtra(Extras.COINIFY_OUT_AMOUNT); received.setText(String.format("%s %s", tvapx, getIntent().getStringExtra(Extras.COINIFY_OUT_AMOUNT_CUR))); email.setText(sharedManager.getCoinifyEmail()); coinify_bank_chb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { btnNext.setEnabled(true); } else { btnNext.setEnabled(false); } } }); }
Example 11
Source File: TagDescriptor.java From metadata-extractor with Apache License 2.0 | 5 votes |
@Nullable protected static String getFStopDescription(double fStop) { DecimalFormat format = new DecimalFormat("0.0"); format.setRoundingMode(RoundingMode.HALF_UP); return "f/" + format.format(fStop); }
Example 12
Source File: Convert.java From alpha-wallet-android with MIT License | 5 votes |
public static String getEthStringSzabo(BigInteger szabo) { BigDecimal ethPrice = fromWei(toWei(new BigDecimal(szabo), Unit.SZABO), Unit.ETHER); DecimalFormat df = new DecimalFormat("0.#####"); df.setRoundingMode(RoundingMode.CEILING); return df.format(ethPrice); }
Example 13
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 14
Source File: Utils.java From KA27 with Apache License 2.0 | 5 votes |
public static String round(double value, int places) { StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < places; i++) stringBuilder.append("#"); DecimalFormat df = new DecimalFormat("#." + stringBuilder.toString()); df.setRoundingMode(RoundingMode.CEILING); return df.format(value); }
Example 15
Source File: CurrencyUtils.java From bitcoinpos with MIT License | 5 votes |
public static String getBtcFromLocalCurrency(String amount) { ExchangeRates exchangeRates = ExchangeRates.getInstance(); // the following was losing precision at every toggling!! //double newAmount = Double.parseDouble(currentAmount) * exchangeRates.getLocalToBtcRate(); double newAmount = Double.parseDouble(amount) / exchangeRates.getBtcToLocalRate(); DecimalFormat formatter = new DecimalFormat("#.########", DecimalFormatSymbols.getInstance( Locale.ENGLISH )); formatter.setRoundingMode( RoundingMode.HALF_UP ); return formatter.format(newAmount); }
Example 16
Source File: FormatUtil.java From ClockView with Apache License 2.0 | 5 votes |
public static double formatDouble2Db(double value, String format, RoundingMode mode) { DecimalFormat df = getDecimal(format); if (mode != null) { df.setRoundingMode(mode); } return Double.parseDouble(df.format(value)); }
Example 17
Source File: OpenViduTestAppE2eTest.java From openvidu with Apache License 2.0 | 5 votes |
private void checkMultimediaFile(File file, boolean hasAudio, boolean hasVideo, double duration, String resolution, String audioDecoder, String videoDecoder, boolean checkAudio) throws IOException { // Check tracks, duration, resolution, framerate and decoders MultimediaFileMetadata metadata = new MultimediaFileMetadata(file.getAbsolutePath()); if (hasVideo) { if (checkAudio) { if (hasAudio) { Assert.assertTrue("Media file " + file.getAbsolutePath() + " should have audio", metadata.hasAudio() && metadata.hasVideo()); Assert.assertTrue(metadata.getAudioDecoder().toLowerCase().contains(audioDecoder)); } else { Assert.assertTrue("Media file " + file.getAbsolutePath() + " should have video", metadata.hasVideo()); Assert.assertFalse(metadata.hasAudio()); } } if (resolution != null) { Assert.assertEquals(resolution, metadata.getVideoWidth() + "x" + metadata.getVideoHeight()); } Assert.assertTrue(metadata.getVideoDecoder().toLowerCase().contains(videoDecoder)); } else if (hasAudio && checkAudio) { Assert.assertTrue(metadata.hasAudio()); Assert.assertFalse(metadata.hasVideo()); Assert.assertTrue(metadata.getAudioDecoder().toLowerCase().contains(audioDecoder)); } else { Assert.fail("Cannot check a file witho no audio and no video"); } // Check duration with 1 decimal precision DecimalFormat df = new DecimalFormat("#0.0"); df.setRoundingMode(RoundingMode.UP); log.info("Duration of {} according to ffmpeg: {} s", file.getName(), metadata.getDuration()); log.info("Duration of {} according to 'duration' property: {} s", file.getName(), duration); log.info("Difference in s duration: {}", Math.abs(metadata.getDuration() - duration)); final double difference = 10; Assert.assertTrue( "Difference between recording entity duration (" + duration + ") and real video duration (" + metadata.getDuration() + ") is greater than " + difference + " in file " + file.getName(), Math.abs((metadata.getDuration() - duration)) < difference); }
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: DoubleToString.java From tutorials with MIT License | 4 votes |
public static String truncateWithDecimalFormat(double d) { DecimalFormat df = new DecimalFormat("#,###"); df.setRoundingMode(RoundingMode.FLOOR); return df.format(d); }
Example 20
Source File: FormatDecimal.java From levelup-java-examples with Apache License 2.0 | 3 votes |
@Test public void format_decimal_with_rounding_mode () { double hdTv = 1229.99; DecimalFormat df = new DecimalFormat("###,###"); df.setRoundingMode(RoundingMode.HALF_UP); assertEquals("1,230", df.format(hdTv)); }