2014-01-21 60 views
0

我有一個功能叫做階乘,它計算階乘的數量大,回報BidDecimal格式的BigDecimal串用科學記數法,反之亦然

BigDecimal temp_val1 = factorial(555); 

上面給出66140856092779467090983316712427699021235xxxxxxxxxxxxxxxxxxxxx

現在我不得不格式化BigDecimal值以字符串與科學計數法

NumberFormat sci_formate = new DecimalFormat("0.#####E0"); 
String temp_s1 = sci_formate.format(temp_val1); 

以上給出6.61409E1283

現在我需要字符串temp_s1(6.61409E1283)返回BigDecimal,它給人temp_val1的值轉換.... ????那怎麼辦....

回答

1

試試這個

BigDecimal temp_val1 = new BigDecimal("6.61409E1283"); 

格式化使用

BigDecimal.toEngineeringString() 
+0

的BigDecimal temp_val1 =新的BigDecimal( 「6.61409E1283」);給出6.61409E + 1283。 BigDecimal.toEngineeringString()返回小數的字符串表示形式,如何將此字符串轉換爲bigdecimal? –

+0

你可以不區分字符串爲BigDecimal可以解析它,新的BigDecimal( 「6.61409E1283」)解析它 –

+0

的BigDecimal temp_val1 =階乘(555);給出66140856092779467090983316712427699021235xxxxxxxxxxxxxxxxxxxxx。 現在我將使用DecimalFormat格式化以科學記數法顯示。 NumberFormat sci_formate = new DecimalFormat(「0。##### E0」); String temp_s1 = sci_formate.format(temp_val1);這給出6.61409E1283。 現在我需要把這個字符串(6.61409E1283)返回BigDecimal,它提供了相同的值,temp_val1轉換...... –