Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. 330.39991833
  2. 0.001
  3. 14.64530319
  4. 0.25
  5. 254.16991217
  6.  
  7. 330.23'59"
  8. 0.00'03"
  9. 14.38'43"
  10. 0.15'00"
  11. 254.10'11"
  12.  
  13. public static void ConvertToMinSec(string path)
  14. {
  15. using (StreamReader reader = File.OpenText(path))
  16. {
  17.  
  18.  
  19. while (!reader.EndOfStream)
  20. {
  21. var degreeValues = reader.ReadLine();
  22. if (!string.IsNullOrWhiteSpace(degreeValues))
  23. {
  24. var totalVal = degreeValues.Split('.');
  25. if (totalVal.Length == 1)
  26. {
  27. var temp = totalVal[0] + ".0";
  28. totalVal = temp.Split('.');
  29. }
  30. var intPart = totalVal[0];
  31. var decimalPart = "0." + totalVal[1];
  32. decimal minutes;
  33. decimal.TryParse(decimalPart, out minutes);
  34.  
  35. minutes = decimal.Multiply(minutes, 60);
  36. var minutePart = (int)minutes;
  37. var remainingDecimal = minutes.ToString().Split('.');
  38. if (remainingDecimal.Length == 1)
  39. {
  40. var tempDecimal = remainingDecimal[0] + ".0";
  41. remainingDecimal = tempDecimal.Split('.');
  42. }
  43.  
  44.  
  45. decimal seconds;
  46. decimal.TryParse("0." + remainingDecimal[1], out seconds);
  47. seconds = seconds*60;
  48. var secondsPart = (int) seconds;
  49. var report = string.Format("{0}"+"."+"{1:00}"+"'"+"{2:00}"+'"', intPart,
  50. minutePart, secondsPart);
  51.  
  52. Console.WriteLine(report);
  53. }
  54. }
  55. }
  56.  
  57. public static string ToDegMinSec(double dec)
  58. {
  59. int degrees = (int)dec;
  60. dec = 60 * (dec - degrees);
  61. int minutes = (int)dec;
  62. dec = 60 * (dec - minutes);
  63. int seconds = (int)dec;
  64. return string.Format("{0}.{1:00}'{2:00}"", degrees, minutes, seconds);
  65. }
  66.  
  67. var minutes = Convert.ToDecimal("0." + totalVal[1])*60;
  68. var remainingDecimal = minutes.ToString().Split('.');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement