今天在做excel导出的时候,导出的表格中长度大于11的数字会自动用科学计数法显示。
一开始,我想着直接将数据全部转为string类型,没想到还是无法解决问题(可能是excel工具自动识别数字,又将其转成科学计数了)。
后来通过百度发现了多种解决方法,下面两种个人觉得效率比较高,代码改动最少:
- 将要导出的数转为BigDecimal类型,在使用toPlainString转换为String类型
BigDecimal bigDecimal = new BigDecimal(value);
String out = bigDecimal.toPlainString();
- 通过DecimalFormat将数字转换String类型
String out = new DecimalFormat("0.00").format(value);
(其中0.00表示保留的位数)
mysql针对数字类型的转换建议使用convert和cast函数,
format(param,2)
convert(param, decimal(12,2)) 其中12是数字的个数
cast(param as decimal(12,2))
1万+




被折叠的 条评论
为什么被折叠?



