我有這個程序從雙變量中獲取所有數字,刪除小數點和小數點並分別添加每個數字。這裏是:c#使用雙數時的大數字表示
static void Main(string[] args)
{
double input = double.Parse(Console.ReadLine());
char[] chrArr = input.ToString().ToCharArray();
input = 0;
foreach (var ch in chrArr)
{
string somestring = Convert.ToString(ch);
int someint = 0;
bool z = int.TryParse(somestring, out someint);
if (z == true)
{
input += (ch - '0');
}
}
問題是,例如當我輸入「9999999999999999999999999999999 ......」等等,它被表示爲1.0E+254
什麼,所以我的計劃只是增加了1+0+2+5+4
和完成。有沒有有效的方法來正確地工作?我嘗試使用字符串instad的雙重,但它的作品太慢..
你應該知道'double'將不能保存這個數字。改爲尋找'BigDecimal'。 –
http://stackoverflow.com/questions/1319191/how-to-convert-double-to-string-without-the-power-to-10-representation-e-05 – algreat
可能的重複[Double to string conversion without without科學記數法](http://stackoverflow.com/questions/1546113/double-to-string-conversion-without-scientific-notation) –