2014-09-26 44 views
-2

我怎樣才能將一個雙變量在java中變成兩位小數?我想將一個雙變量四捨五入到兩位小數

+0

你想要一個字符串或double結果? – Bohemian 2014-09-26 12:24:12

+0

檢查以下鏈接: http://stackoverflow.com/q/22646612/4082061 http://stackoverflow.com/q/153724/4082061 – 2014-09-26 12:25:00

回答

0

yourNewFormatedDouble =新DecimalFormat的格式(yourOldDoubleHere)( 「###」。)。

+0

凡本語法必須在我的代碼寫? – sana 2014-09-26 12:26:52

0
DecimalFormat df = new DecimalFormat("0.00##"); 
String result = df.format(myDouble);