Java Double类型如何不科学计数法显示

今天遇到个很棘手但难以解决的问题!就是关于Double显示科学计数法问题!


比如10000000.21的Double类型 却显示成10.00000021E7  其实如果这个用String 类型输出的话很容易解决。

如:

DecimalFormat df = new DecimalFormat("0.00"); 
System.out.println(df.format(a));

public static String formatNum(double value)
    {
        String retValue = null;
        DecimalFormat df = new DecimalFormat();
        df.setMinimumFractionDigits(0);
        df.setMaximumFractionDigits(2);
        retValue = df.format(value);
        retValue = retValue.replaceAll(",", "");
        return retValue;
    }
都可以不以科学计数法显示的 但是返回的都是String 类型

大家有没有考虑过。

如果让Double类型不变的前提,非科学计数法显示了。?

     到最后实在没办法 。只有在页面做文章了。

当在页面获取数据显示前 ,对他格式化下!  

用FMT:FORMATNUMBER  标签;试试

具体写法:

<fmt:formatNumber value="${caseForm.caseBean.payinfo.paymentFee}" pattern="0.00"/>

原文传送门:http://www.blogjava.net/javacql/archive/2009/11/13/302168.html

于2017-12-18补充

import java.text.DecimalFormat;
import java.text.NumberFormat;

public class TestUtil {
	public static String formatNum(double value) {
		String retValue = null;
		DecimalFormat df = new DecimalFormat();
		df.setMinimumFractionDigits(0);
		df.setMaximumFractionDigits(2);
		retValue = df.format(value);
		retValue = retValue.replaceAll(",", "");
		return retValue;
	}

	public static String formatDouble(double value) {
		String retValue = null;
		NumberFormat format = NumberFormat.getInstance();
		format.setMinimumFractionDigits(0);
		format.setMaximumFractionDigits(2);
		format.setGroupingUsed(false);
		retValue = format.format(value);
		retValue = retValue.replaceAll(",", "");
		return retValue;
	}

	public static void main(String[] args) {
		double value = 10000000.21;
		System.out.println(formatNum(value));
		System.out.println(formatDouble(value));
	}
}


  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值