static void Main(string[] args) { SUBS subs = new SUBS(); string s1 = "987,654,321,000,987,654,321,000.0111111"; string s2 = "111,111,111,111,111,111,111,111.9"; Console.WriteLine(" {0}", s1); Console.WriteLine(" {0}", s2); Console.WriteLine(" -"); Console.WriteLine("{0}", subs.subs(s1, s2)); }
public string math(string s1, string s2, bool shows) { int counter = 0; string ssss = ""; char c = ' '; int i = 0; bool exits = false; bool exits2 = false; int pos = 0; int st = 0; bool b = false; int point1s = 0; int point2s = 0; int point3s = 0; int pos1 = 0; number = ""; string ss0 = ""; string ss1 = s1; string ss2 = s2; if (shows) { Console.WriteLine(" {0}", s1); } if (shows) { Console.WriteLine(" {0}", s2); } if (shows) { Console.WriteLine("----------------"); } ss1 = ss1.Replace(",", ""); ss2 = ss2.Replace(",", ""); ss1 = ss1.Replace("'", ""); ss2 = ss2.Replace("'", ""); st = ss1.IndexOf("."); if (st < 0) { st = ss1.Length; } point1s = ss1.Length - st - 1; if (point2s < 0) { point2s = 0; } st = ss2.IndexOf("."); if (st < 0) { st = ss2.Length; } point2s = ss2.Length - st - 1; if (point2s < 0) { point2s = 0; } ss1 = ss1.Replace(".", ""); ss2 = ss2.Replace(".", ""); if (ss1.Length < ss2.Length) { number = "0"; exits = true; } else { number1 = sub.left(ss1, ss2.Length); pos = ss2.Length; } ss2 = Removezeros(ss2); while (!exits) { exits2 = false; if (pos > ss1.Length) { exits2 = true; } while (!exits2) { b = true; number1 = Removezeros(number1); if (number1.Length == ss2.Length) { b = sub.test(number1, "0", ss2, "0"); } if (number1.Length > ss2.Length) { b = false; } if (number1.Length < ss2.Length) { b = true; } if (b) { number = number + "0"; if (pos < ss1.Length) { number1 = number1 + ss1[pos]; } pos++; } else { exits2 = true; } if (pos > ss1.Length) { exits2 = true; } } number1 = Removezeros(number1); if (shows) { Console.WriteLine("{0}", number1); } if (pos <= ss1.Length) { for (i = 9; i > 0; i--) { c = Convert.ToChar(i + Convert.ToInt16('0')); number1out = mul.mulsn(mul.sinvert(ss2), c, false, 0); number1out = Removezeros(number1out); number1 = Removezeros(number1); if (number1.Length == number1out.Length) { b = sub.test(number1, "0", number1out, "0"); } if (number1.Length > number1out.Length) { b = false; } if (number1.Length < number1out.Length) { b = true; } if (!b) { number = number + c; i = -1; number1 = sub.subs(number1 + ".0", number1out + ".0"); number1 = number1.Replace(",", ""); number1 = number1.Replace(".0", ""); number1 = number1.Replace(".", ""); } } } number1 = Removezeros(number1); if (shows) { Console.WriteLine("{0}", number1); } number1 = Removezeros(number1); b = true; if (number1.Length == ss2.Length) { b = sub.test(number1, "0", ss2, "0"); } if (number1.Length > ss2.Length) { b = false; } if (number1.Length < ss2.Length) { b = true; } if (b) { if (pos < ss1.Length) { number1 = number1 + ss1[pos]; } pos++; } if (pos > ss1.Length) { exits = true; } } if (shows) { Console.WriteLine("----------------"); } if (number == "") { number = "0"; } number = Removezeros(number).Trim(); point3s = point1s; point1s = number.Length - point1s - 1; if (point1s < 0) { pos1 = -point1s; for (i = 0; i < pos1; i++) { number = "0" + number; } } if (point2s > 0) { pos1 = point2s; for (i = 0; i < pos1; i++) { number = number + "0"; } } point1s = number.Length - point3s - 1; ss1 = ""; ss0 = ""; for (i = 0; i < number.Length; i++) { if (i <= point1s) { ss0 = ss0 + number[i]; } else { ss1 = ss1 + number[i]; } } ss0 = mul.sinvert(ss0); ss0 = mul.separetes(ss0); ss0 = mul.sinvert(ss0); ss1 = mul.separetes(ss1); number = ss0 + "." + ss1; if (shows) { Console.WriteLine(" {0}", number); } return(number); }