本文介绍BigDecimal的3个toString方法的区别。

BigDecimal类有3个toString方法,分别是toEngineeringString、toPlainString和toString,

从BigDecimal的注释中可以看到这3个方法的区别:

toEngineeringString:有必要时使用工程计数法。工程记数法是一种工程计算中经常使用的记录数字的方法,与科学技术法类似,但要求10的幂必须是3的倍数

toPlainString:不使用任何指数

toString:有必要时使用科学计数法

 不使用指数 科学记数法 工程记数法
2700 2.7 × 10³ 2.7 × 10³
27000 2.7 × 10⁴ 27 × 10³
270000 2.7 × 10⁵ 270 × 10³
2700000 2.7 × 10⁶ 2.7 × 10⁶

看看如下程序示例

import java.math.BigDecimal;

public class BigDecimalDemo {
public static void main(String[] args) {
BigDecimal bg = new BigDecimal("1E11");
System.out.println(bg.toEngineeringString());
System.out.println(bg.toPlainString());
System.out.println(bg.toString());
}
}
 

输出

  • 100E+9
  • 100000000000
  • 1E+11

本文来自:http://www.hiwzc.com/bigdecimal-tostring.html

最新文章

  1. Ansible-Tower快速入门-6.查看tower的仪表板【翻译】
  2. hdu 1506
  3. BZOJ 1042 硬币购物(完全背包+DP)
  4. 学会使用JDK API
  5. unity3d发布Android程序
  6. sed示例
  7. [c language] getopt
  8. LA - 5031 - Graph and Queries
  9. How can I get an object's absolute position on the page in Javascript?
  10. crm采用soap删除记录
  11. H5万能选择器:iosselect
  12. ES6(二) Destructuring-变量的解构赋值
  13. 初学高级程序设计 shell编程
  14. LNK2022: 元数据操作失败(8013118D): 重复类型(FactoryContext)中的布局信息不一致: (0x02000230)
  15. 返回枚举中的desciption
  16. log4net架构、配置、使用
  17. ArrayList 初探
  18. propsData 选项 全局扩展的数据传递
  19. cipher的各个模式
  20. Javascrip获取页面URL信息

热门文章

  1. fiddler笔记:状态面板
  2. 【Trie】背单词
  3. 「网络流 24 题」最长 k 可重区间集
  4. spring-boot-plusV1.2.3发布,CentOS快速安装环境/构建/部署/启动项目
  5. LeetCode 腾讯精选50题--求众数
  6. 对数据库ID进行散裂化计算
  7. python读取ubuntu系统磁盘挂载情况
  8. 处理器拦截器(HandlerInterceptor)详解(转)
  9. Spring Cloud(八)高可用的分布式配置中心 Spring Cloud Config
  10. 【python+selenium】selenium grid(分布式)