Advertisement
Guest User

Untitled

a guest
Aug 31st, 2015
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. 10.50 = 10 and 50
  2. 10.45 = 10 and 45
  3. 10.5 = 10 and 50
  4.  
  5. string s = inputValue.ToString("0.00", CultureInfo.InvariantCulture);
  6. string[] parts = s.Split('.');
  7. int i1 = int.Parse(parts[0]);
  8. int i2 = int.Parse(parts[1]);
  9.  
  10. double number;
  11.  
  12. long intPart = (long) number;
  13. double fractionalPart = number - intPart;
  14.  
  15. static void Main(string[] args)
  16. {
  17. decimal number = 10123.51m;
  18. int whole = (int)number;
  19. decimal precision = (number - whole) * 100;
  20.  
  21. Console.WriteLine(number);
  22. Console.WriteLine(whole);
  23. Console.WriteLine("{0} and {1}",whole,(int) precision);
  24. Console.Read();
  25. }
  26.  
  27. double num = 10.5;
  28. int remainder = num % 1
  29.  
  30. string s = input.ToString();
  31. string[] parts = s.Split('.');
  32.  
  33. public string Time_In_Absolute(double time)
  34. {
  35. time = Math.Round(time, 2);
  36. string[] timeparts = time.ToString().Split('.');
  37. timeparts[1] = "." + timeparts[1];
  38. double Minutes = double.Parse(timeparts[1]);
  39. Minutes = Math.Round(Minutes, 2);
  40. Minutes = Minutes * (double)60;
  41. return string.Format("{0:00}:{1:00}",timeparts[0],Minutes);
  42. //return Hours.ToString() + ":" + Math.Round(Minutes,0).ToString();
  43. }
  44.  
  45. string s = "10.5";
  46. string[] s1 = s.Split(new char[] { "." });
  47. string first = s1[0];
  48. string second = s1[1];
  49.  
  50. foreach (double x in new double[]{10.45, 10.50, 10.999, -10.323, -10.326, 10}){
  51. int i = (int)Math.Truncate(x);
  52. int f = (int)Math.Round(100*Math.Abs(x-i));
  53. if (f==100){ f=0; i+=(x<0)?-1:1; }
  54. Console.WriteLine("("+i+", "+f+")");
  55. }
  56.  
  57. (10, 45)
  58. (10, 50)
  59. (11, 0)
  60. (-10, 32)
  61. (-10, 33)
  62. (10, 0)
  63.  
  64. double number = 4140 / 640; //result is 6.46875 for example
  65.  
  66. int intPart = (int)number; //just convert to int, loose the dec.
  67. int fractionalPart = (int)((position - intPart) * 1000); //rounding was not needed.
  68. //this procedure will create two variables used to extract [iii*].[iii]* from iii*.iii*
  69.  
  70. "10.50".Split('.').Select(int.Parse);
  71.  
  72. /// <summary>
  73. /// Get the integral and floating point portions of a Double
  74. /// as separate integer values, where the floating point value is
  75. /// raised to the specified power of ten, given by 'places'.
  76. /// </summary>
  77. public static void Split(Double value, Int32 places, out Int32 left, out Int32 right)
  78. {
  79. left = (Int32)Math.Truncate(value);
  80. right = (Int32)((value - left) * Math.Pow(10, places));
  81. }
  82.  
  83. public static void Split(Double value, out Int32 left, out Int32 right)
  84. {
  85. Split(value, 1, out left, out right);
  86. }
  87.  
  88. Int32 left, right;
  89.  
  90. Split(10.50, out left, out right);
  91. // left == 10
  92. // right == 50
  93.  
  94. Split(10.50, 5, out left, out right);
  95. // left == 10
  96. // right == 500000
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement