0
嘿,我想催產素能夠在形式使用此代碼,但我不experianced不夠,想知道如何以及在何處改變這種代碼可以使用它的形式試圖改變公衆無效等,但只能得到錯誤信息如何使用代碼從控制檯應用程序的形式應用
static String NumWords(double n) //converts double to words
{
string[] numbersArr = new string[] { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
string[] tensArr = new string[] { "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninty" };
string[] suffixesArr = new string[] { "thousand", "million", "billion", "trillion", "quadrillion", "quintillion", "sextillion", "septillion", "octillion", "nonillion", "decillion", "undecillion", "duodecillion", "tredecillion", "Quattuordecillion", "Quindecillion", "Sexdecillion", "Septdecillion", "Octodecillion", "Novemdecillion", "Vigintillion" };
string words = "";
bool tens = false;
if (n < 0)
{
words += "negative ";
n *= -1;
}
int power = (suffixesArr.Length + 1) * 3;
while (power > 3)
{
double pow = Math.Pow(10, power);
if (n >= pow)
{
if (n % pow > 0)
{
words += NumWords(Math.Floor(n/pow)) + " " + suffixesArr[(power/3) - 1] + ", ";
}
else if (n % pow == 0)
{
words += NumWords(Math.Floor(n/pow)) + " " + suffixesArr[(power/3) - 1];
}
n %= pow;
}
power -= 3;
}
if (n >= 1000)
{
if (n % 1000 > 0) words += NumWords(Math.Floor(n/1000)) + " thousand, ";
else words += NumWords(Math.Floor(n/1000)) + " thousand";
n %= 1000;
}
if (0 <= n && n <= 999)
{
if ((int)n/100 > 0)
{
words += NumWords(Math.Floor(n/100)) + " hundred";
n %= 100;
}
if ((int)n/10 > 1)
{
if (words != "")
words += " ";
words += tensArr[(int)n/10 - 2];
tens = true;
n %= 10;
}
if (n < 20 && n > 0)
{
if (words != "" && tens == false)
words += " ";
words += (tens ? "-" + numbersArr[(int)n - 1] : numbersArr[(int)n - 1]);
n -= Math.Floor(n);
}
}
return words;
}
它是在一個控制檯 –
確實出現錯誤,其中origanly做? – Aimnox
你不能使它成爲'void',因爲它返回一個值。正確的用法就像'var returnedWords = NumWords(123456789);'。字符串'returnedWords'然後將有一個值表示傳遞的數字(123456789)作爲單詞。 – Equalsk