BigDecimal保留三位小数
时间: 2023-09-09 17:10:37 浏览: 185
Java指定保留小数位数的方法
为了保留BigDecimal的三位小数,可以使用setScale方法。例如,将一个BigDecimal变量a保留三位小数可以使用以下代码:a = a.setScale(3, BigDecimal.ROUND_HALF_UP);这里的3表示要保留的小数位数,ROUND_HALF_UP表示采用四舍五入的方式进行进位。通过这个方法,可以确保BigDecimal的值只保留三位小数。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [java8 BigDecimal 除法保留三位小数 后面小数进位处理](https://blog.csdn.net/weixin_42613018/article/details/129455239)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [BigDecimal的使用](https://blog.csdn.net/X_kai_style/article/details/86290149)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [整理后java开发全套达内学习笔记(含练习)](https://download.csdn.net/download/lq_1987/3343031)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文