How to Convert Degrees into Double

106°46'21.68 convert it to

106.66 for example.

What would be a good code for that? I am newbie

Take the seconds, divide it by 60

21.68 / 60 = 0.36 (this is how many decimal minutes the seconds equal)

Take the minutes, add the value above

46+0.36 = 46.36 (this is how many decimal minutes you have, with the seconds on the end in decimal)

Take this minutes total, divide by 60

46.36 / 60 = 0.77 This is how many degrees the minutes and seconds make

Take the number of degrees from the position and add this

106 + 0.77 = 106.77 degrees, in decimal form.
Any built in function for that?

Okay, so first I would need to split the number with get token thingy ha?
How do you intend to get the value 106°46'21.68 into the code? Is it being read from a file? Typed in? Does it already exist as some kind of position type in your code?

There is a built in operator for dividing numbers. It's this:

 
/
Last edited on
Let's just say that we have a string

std::string a="106°46'21.68";

Now how would I do that?

I will get the number possibly from website but that's another problem.
http://www.cplusplus.com/articles/numb_to_text/

^- This may be of some use to you
let me guess first some input stream.

istream thestream;
then

thestream>>degree;
thestream>>trash;
thestream>>minute;
thestream>>trash;
thestream>>second;


Hmm.. some bad typing I think. What's the difference between input stream and output stream anyway?
I can't really answer that :O I've never had to write the iostream header from scratch, nor have I seen it. I'd assume the only difference is a flag on the class that signals whether you are reading or writing.
Topic archived. No new replies allowed.