本文介紹了Java 格式帶逗號和 2 位小數的 BigDecimal 數字的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
我想用逗號和 2 個小數點格式化 BigDecimal 數字.例如
I want to format BigDecimal Numbers with comma and 2 decimal points. e.g.
Amount is: 5.0001 and formatted to: 5.00
Amount is: 999999999.999999 and formatted to: 999,999,999.99
Amount is: 1000.4999 and formatted to: 1,000.49
Amount is: 9999.089 and formatted to: 9,999.08
Amount is: 0.19999 and formatted to: 0.19
Amount is: 123456.99999999 and formatted to: 123,456.99
推薦答案
這樣應該就可以得到結果了.
This should be enough to get the results.
String.format("%,.2f", amount.setScale(2, RoundingMode.DOWN));
這篇關于Java 格式帶逗號和 2 位小數的 BigDecimal 數字的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!