2016-07-05 47 views
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; 

    } 
+0

它是在一个控制台 –

+0

确实出现错误,其中origanly做? – Aimnox

+0

你不能使它成为'void',因为它返回一个值。正确的用法就像'var returnedWords = NumWords(123456789);'。字符串'returnedWords'然后将有一个值表示传递的数字(123456789)作为单词。 – Equalsk

回答

0

可以包括按钮点击envent此功能,或者也可以调用这个函数的onchange文本框的事件,这将用于输入数字小值。

  1. 如果要调用从按钮点击此功能则只是通过文本框的值作为输入到该函数

// COnvertBtn is button id, on click of which function will get call //But make sure that text box named as txtNumber should contain number void ConvertBtn_Click(Object sender, EventArgs e) { string number = NumWords(Convert.ToDouble(txtNumber.Text)); }

  • 否则可以调用直接从JavaScript函数,在这里你需要做一些改变,以作为输入的数据类型将是文本

  • 问候, 符合

    相关问题