setscale保留2位小数
时间: 2023-10-13 11:04:19 浏览: 111
setScale方法是用于设置BigDecimal对象的小数位数并进行舍入处理的。在给定的例子中,setScale(2, RoundingMode.HALF_UP)将保留两位小数,并且使用四舍五入的方式进行舍入处理。具体来说,它会把小数位数设置为2,并且当需要进行舍入时,如果小数部分大于等于0.5,就向上舍入;否则,向下舍入。这样就可以保留两位小数。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [java BigDecimalUtil 保留两位小数 去掉小数位无效0并转换为String,nullToZero](https://download.csdn.net/download/weixin_47315082/88134538)[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_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [Bigdecimal保留小数点情况](https://blog.csdn.net/morality_hj/article/details/118303026)[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_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [java保留小数点的方式](https://blog.csdn.net/weixin_43172997/article/details/102176341)[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_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文