Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Degrees, minutes and seconds to Decimal Degrees

Degrees, minutes and seconds to Decimal Degrees

Scheduled Pinned Locked Moved C#
csharp
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Darrall
    wrote on last edited by
    #1

    I have been asking around to see if there is an existing class method in C# to do this and it appears not so I worked out my own methods if anyone is interested or needs them.

    // angle or bearing in degrees, minutes and seconds
    double angle = 45.2413;

            //degrees, minutes and seconds
            double degminsec = angle;
            // decimal seconds
            double decsec = (degminsec \* 100 - Math.Truncate(degminsec\*100)) / .6;
            //degrees and minutes
            double degmin = (Math.Truncate(degminsec \* 100) + decsec) / 100;
            //degrees
            double deg = Math.Truncate(degmin);
            //decimal degrees
            double decdeg = deg + (degmin - deg) / .6;
    

    And this is to go back the other way:

    // angle in decimal degrees
    double angle = 45.4036;

            //decimal degrees
            double decdeg = angle;
            //integer is minutes and the decimal is decimal seconds
            double minsec = (decdeg - Math.Truncate(decdeg)) \* 60;
            //seconds
            double sec = (minsec - Math.Truncate(minsec)) \* 60; 
            //degrees, miutes and seconds
            double degminsec = (Math.Truncate(sec) / 10000) + (Math.Truncate(minsec) / 100) + Math.Truncate(decdeg);
    
    A L T 3 Replies Last reply
    0
    • D Darrall

      I have been asking around to see if there is an existing class method in C# to do this and it appears not so I worked out my own methods if anyone is interested or needs them.

      // angle or bearing in degrees, minutes and seconds
      double angle = 45.2413;

              //degrees, minutes and seconds
              double degminsec = angle;
              // decimal seconds
              double decsec = (degminsec \* 100 - Math.Truncate(degminsec\*100)) / .6;
              //degrees and minutes
              double degmin = (Math.Truncate(degminsec \* 100) + decsec) / 100;
              //degrees
              double deg = Math.Truncate(degmin);
              //decimal degrees
              double decdeg = deg + (degmin - deg) / .6;
      

      And this is to go back the other way:

      // angle in decimal degrees
      double angle = 45.4036;

              //decimal degrees
              double decdeg = angle;
              //integer is minutes and the decimal is decimal seconds
              double minsec = (decdeg - Math.Truncate(decdeg)) \* 60;
              //seconds
              double sec = (minsec - Math.Truncate(minsec)) \* 60; 
              //degrees, miutes and seconds
              double degminsec = (Math.Truncate(sec) / 10000) + (Math.Truncate(minsec) / 100) + Math.Truncate(decdeg);
      
      A Offline
      A Offline
      Abhinav S
      wrote on last edited by
      #2

      Posting this as a tip would perhaps be better than in a forum.

      D 1 Reply Last reply
      0
      • A Abhinav S

        Posting this as a tip would perhaps be better than in a forum.

        D Offline
        D Offline
        Darrall
        wrote on last edited by
        #3

        Ok thanks. I'm new to here so not sure how to do that.

        T 1 Reply Last reply
        0
        • D Darrall

          Ok thanks. I'm new to here so not sure how to do that.

          T Offline
          T Offline
          Tarakeshwar Reddy
          wrote on last edited by
          #4

          You will find it under articles menu on the top Post Tip & Trick[^]


          Tarakeshwar Reddy There are two kinds of people, those who do the work and those who take the credit. Try to be in the first group; there is less competition there. - Indira Gandhi

          1 Reply Last reply
          0
          • D Darrall

            I have been asking around to see if there is an existing class method in C# to do this and it appears not so I worked out my own methods if anyone is interested or needs them.

            // angle or bearing in degrees, minutes and seconds
            double angle = 45.2413;

                    //degrees, minutes and seconds
                    double degminsec = angle;
                    // decimal seconds
                    double decsec = (degminsec \* 100 - Math.Truncate(degminsec\*100)) / .6;
                    //degrees and minutes
                    double degmin = (Math.Truncate(degminsec \* 100) + decsec) / 100;
                    //degrees
                    double deg = Math.Truncate(degmin);
                    //decimal degrees
                    double decdeg = deg + (degmin - deg) / .6;
            

            And this is to go back the other way:

            // angle in decimal degrees
            double angle = 45.4036;

                    //decimal degrees
                    double decdeg = angle;
                    //integer is minutes and the decimal is decimal seconds
                    double minsec = (decdeg - Math.Truncate(decdeg)) \* 60;
                    //seconds
                    double sec = (minsec - Math.Truncate(minsec)) \* 60; 
                    //degrees, miutes and seconds
                    double degminsec = (Math.Truncate(sec) / 10000) + (Math.Truncate(minsec) / 100) + Math.Truncate(decdeg);
            
            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            The only problem with these conversions is that you will get incorrect answers. Try running a few tests to see what happens when converting between decimal values and floating point.

            txtspeak is the realm of 9 year old children, not developers. Christian Graus

            1 Reply Last reply
            0
            • D Darrall

              I have been asking around to see if there is an existing class method in C# to do this and it appears not so I worked out my own methods if anyone is interested or needs them.

              // angle or bearing in degrees, minutes and seconds
              double angle = 45.2413;

                      //degrees, minutes and seconds
                      double degminsec = angle;
                      // decimal seconds
                      double decsec = (degminsec \* 100 - Math.Truncate(degminsec\*100)) / .6;
                      //degrees and minutes
                      double degmin = (Math.Truncate(degminsec \* 100) + decsec) / 100;
                      //degrees
                      double deg = Math.Truncate(degmin);
                      //decimal degrees
                      double decdeg = deg + (degmin - deg) / .6;
              

              And this is to go back the other way:

              // angle in decimal degrees
              double angle = 45.4036;

                      //decimal degrees
                      double decdeg = angle;
                      //integer is minutes and the decimal is decimal seconds
                      double minsec = (decdeg - Math.Truncate(decdeg)) \* 60;
                      //seconds
                      double sec = (minsec - Math.Truncate(minsec)) \* 60; 
                      //degrees, miutes and seconds
                      double degminsec = (Math.Truncate(sec) / 10000) + (Math.Truncate(minsec) / 100) + Math.Truncate(decdeg);
              
              T Offline
              T Offline
              Tarakeshwar Reddy
              wrote on last edited by
              #6

              How about just doing something like

              deg + min / 60 + sec / 3600


              Tarakeshwar Reddy There are two kinds of people, those who do the work and those who take the credit. Try to be in the first group; there is less competition there. - Indira Gandhi

              modified on Saturday, March 27, 2010 3:49 PM

              D 1 Reply Last reply
              0
              • T Tarakeshwar Reddy

                How about just doing something like

                deg + min / 60 + sec / 3600


                Tarakeshwar Reddy There are two kinds of people, those who do the work and those who take the credit. Try to be in the first group; there is less competition there. - Indira Gandhi

                modified on Saturday, March 27, 2010 3:49 PM

                D Offline
                D Offline
                Darrall
                wrote on last edited by
                #7

                That would be fine except that it is entered in the format ##.####. You would have to use 3 separate input modes otherwise and that isn't practical for surveying.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups