How to Avoid Scientific Notation in Double?

前端 未结 5 1458
走了就别回头了
走了就别回头了 2020-11-30 10:23

Here is my simple code

        @Override
    public void onClick(View v) {
        try {
            double price = Double.parseDouble(ePrice.getText().toStr         


        
相关标签:
5条回答
  • 2020-11-30 10:38

    You can try this DecimalFormat

    DecimalFormat decimalFormatter = new DecimalFormat("############");
    number.setText(decimalFormatter.format(Double.parseDouble(result)));
    
    0 讨论(0)
  • 2020-11-30 10:47

    I would suggest using BigDecimals instead of doubles. That way you will have a more precise control over your calculation precision. Also you can get a non-scientific String using BigDecimal.toPlainString().

    0 讨论(0)
  • 2020-11-30 10:49

    Check answer here. You can write

    moneyToGet.setText(String.format("%.0f", priceValue));
    
    0 讨论(0)
  • 2020-11-30 10:56

    Use NumberFormater like

    NumberFormat myformatter = new DecimalFormat("########");  
    
    String result = myformatter.format(yourValue);
    
    0 讨论(0)
  • 2020-11-30 10:58
    DecimalFormat decimalFormatter = new DecimalFormat("##.############");
                        decimalFormatter.setMinimumFractionDigits(2);
                        decimalFormatter.setMaximumFractionDigits(15);
    

    This option will help you ##.## suffix 0 before decimal, otherwise output will be .000

     btc.setText(decimalFormatter.format(btcval));
    

    use this for displaying content

    0 讨论(0)
提交回复
热议问题