Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All, I'm posting this question after searching Google, but didn't quite understand. In the following code


C++
CString str1;
str1.Format(_T("%%02d°%%02d'%%1.%dlf\""), val)
//val is an integer


This displays decimal degrees, minutes and seconds. But in the seconds part why is it 1.%dlf, why is the decimal, long n float used and also from my understanding %% means print the percentage but the % symbol is not displayed in my interface.
Posted
Updated 8-May-12 4:07am
Comments
CPallini 8-May-12 9:24am    
It looks just a WRONG format specifier. Do you get the right output?

1 solution

I believe what you pasted there will simply generate a format string (btw it is missing an "integer" parameter)

str1.Format(_T("%%02d°%%02d'%%1.%dlf\""), 5);

will give you:
%02d°%02d'%1.5lf"

I supose this is done so the number of decimals can be dynamically modified (in the example the parameter 5 can be varied). After that string has been created, it is probably used to format the actual string.

E.g:
str2.Format(str1, 1,2,3.45678910);

which will result in something like:
01°02'3.45679"
 
Share this answer
 
Comments
CPallini 8-May-12 9:51am    
Wow, I didn't realize that. 5++.
Code-o-mat 8-May-12 10:10am    
Thanks. :)
Sumal.V 8-May-12 10:09am    
Oops Sorry yes, I have missed the int variable. Have added that now.
But y not just write :

str1.Format(_T("%%02d°%%02d'%%1.%d\""), 5);

In the seconds part, why is lf required?
Code-o-mat 8-May-12 10:20am    
That stands for "long double", check here: http://msdn.microsoft.com/en-us/library/tcxf1dw6%28v=vs.80%29.aspx
Sumal.V 8-May-12 10:21am    
So why combine int with long double?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900