public static string AmtInChinese(int amount) { try { string m_1, m_2, m_3, m_4, m_5, m_6, m_7, m_8, m_9, Num, type; Num = amount.ToString(); type = ""; m_1 = Num; string numNum = "0123456789."; string numChina = "零壹貳參肆伍陸柒捌玖點"; string numChinaWeigh = "個拾佰仟萬拾佰仟億拾佰仟萬"; if (Num.Substring(0, 1) == "0") // 0123 -> 123 { Num = Num.Substring(1, Num.Length - 1); } if (!Num.Contains('.')) { Num += ".00"; } else//123.234 123.23 123.2 { Num = Num.Substring(0, Num.IndexOf('.') + 1 + (Num.Split('.')[1].Length > 2 ? 3 : Num.Split('.')[1].Length)); } m_1 = Num; m_2 = m_1; m_3 = m_4 = ""; //m_2:1234-> 壹貳叁肆 for (int i = 0; i < 11; i++) { m_2 = m_2.Replace(numNum.Substring(i, 1), numChina.Substring(i, 1)); } // m_3:佰拾萬仟佰拾個 int iLen = m_1.Length; if (m_1.IndexOf('.') > 0) { iLen = m_1.IndexOf('.');//獲取整數位數 } for (int j = iLen; j >= 1; j--) { m_3 += numChinaWeigh.Substring(j - 1, 1); } //m_4:2行+3行 for (int i = 0; i < m_3.Length; i++) { m_4 += m_2.Substring(i, 1) + m_3.Substring(i, 1); } //m_5:4行去"0"後拾佰仟 m_5 = m_4; m_5 = m_5.Replace("零拾", "零"); m_5 = m_5.Replace("零佰", "零"); m_5 = m_5.Replace("零仟", "零"); //m_6:00-> 0,000-> 0 m_6 = m_5; for (int i = 0; i < iLen; i++) { m_6 = m_6.Replace("零零", "零"); } //m_7:6行去億,萬,個位"0" m_7 = m_6; m_7 = m_7.Replace("億零萬零", "億零"); m_7 = m_7.Replace("億零萬", "億零"); m_7 = m_7.Replace("零億", "億"); m_7 = m_7.Replace("零萬", "萬"); if (m_7.Length > 2) { m_7 = m_7.Replace("零個", "個"); } //m_8:7行+2行小數-> 數目 m_8 = m_7; m_8 = m_8.Replace("個", ""); if (m_2.Substring(m_2.Length - 3, 3) != "點零零") { m_8 += m_2.Substring(m_2.Length - 3, 3); } //m_9:7行+2行小數-> 價格 m_9 = m_7; m_9 = m_9.Replace("個", "元"); if (m_2.Substring(m_2.Length - 3, 3) != "點零零") { m_9 += m_2.Substring(m_2.Length - 2, 2); m_9 = m_9.Insert(m_9.Length - 1, "角"); m_9 += "分"; } else { m_9 += "整"; } if (m_9 != "零元整") { m_9 = m_9.Replace("零元", ""); } m_9 = m_9.Replace("零分", "整"); if (type == "數量") { return(m_8); } else { return(m_9); } } catch { throw; } }
public static int ControllerNum(InputController controller) { return(Num.Contains(controller) ? Num.ToList().IndexOf(controller) : -1); }