2016-07-05 85 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函數,在這裏你需要做一些改變,以作爲輸入的數據類型將是文本

  • 問候, 符合

    相關問題