欢迎来到我的博客
Civil 3D开发与应用,欢迎加入QQ群:484124761
AutoCAD开发,欢迎加入QQ群:193522571

十进制度转换为度分秒

// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。

//

 

#include "stdafx.h"

#include <iostream>

#include <math.h>

 

using namespace std;

 

struct DMS

{

    DMS(double value)

    {

        degrees = floor(value);

        double rem = (value - degrees) * 60;

        minutes = floor(rem);

        seconds = (rem - minutes) * 60;

    }

 

    operator double() const

    {

        return degrees + minutes / 60 + seconds / 3600;

    }

 

    double degrees;

    double minutes;

    double seconds;

};

int main()

{

 

    DMS dms = DMS(12.35);

    cout << dms.degrees<< "°"<< dms.minutes <<"′" << dms.seconds<<"″"<<endl;

    cout << double(dms) << endl;

return 0;

}

posted @ 2017-11-11 17:20  david96007  阅读(2261)  评论(0编辑  收藏  举报