BigDecimal的3个toString方法
2024-09-05 03:54:16
本文介绍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
最新文章
- Ansible-Tower快速入门-6.查看tower的仪表板【翻译】
- hdu 1506
- BZOJ 1042 硬币购物(完全背包+DP)
- 学会使用JDK API
- unity3d发布Android程序
- sed示例
- [c language] getopt
- LA - 5031 - Graph and Queries
- How can I get an object's absolute position on the page in Javascript?
- crm采用soap删除记录
- H5万能选择器:iosselect
- ES6(二) Destructuring-变量的解构赋值
- 初学高级程序设计 shell编程
- LNK2022: 元数据操作失败(8013118D): 重复类型(FactoryContext)中的布局信息不一致: (0x02000230)
- 返回枚举中的desciption
- log4net架构、配置、使用
- ArrayList 初探
- propsData 选项 全局扩展的数据传递
- cipher的各个模式
- Javascrip获取页面URL信息
热门文章
- fiddler笔记:状态面板
- 【Trie】背单词
- 「网络流 24 题」最长 k 可重区间集
- spring-boot-plusV1.2.3发布,CentOS快速安装环境/构建/部署/启动项目
- LeetCode 腾讯精选50题--求众数
- 对数据库ID进行散裂化计算
- python读取ubuntu系统磁盘挂载情况
- 处理器拦截器(HandlerInterceptor)详解(转)
- Spring Cloud(八)高可用的分布式配置中心 Spring Cloud Config
- 【python+selenium】selenium grid(分布式)