Click here to Skip to main content
Sign Up to vote bad
good
See more: C++
Hello All, I'm posting this question after searching Google, but didn't quite understand. In the following code
 
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 8 May '12 - 3:01
Edited 8 May '12 - 4:07

Comments
CPallini - 8 May '12 - 9:24
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"
  Permalink  
Comments
CPallini - 8 May '12 - 9:51
Wow, I didn't realize that. 5++.
Code-o-mat - 8 May '12 - 10:10
Thanks. :)
Member 8446342 - 8 May '12 - 10:09
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:20
That stands for "long double", check here: http://msdn.microsoft.com/en-us/library/tcxf1dw6%28v=vs.80%29.aspx
Member 8446342 - 8 May '12 - 10:21
So why combine int with long double?
Code-o-mat - 8 May '12 - 10:28
You misunderstand. This: str1.Format("%%1.%dlf", 5); will give you: "%1.5lf" In this context the "lf" after the %d isn't parsed, it's simply output to the generated string as normal text.
Member 8446342 - 8 May '12 - 10:31
Oh well I get that now. Thanks :)
Code-o-mat - 8 May '12 - 10:35
Yourwelcome.

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 449
1 Arun Vasu 253
2 OriginalGriff 210
3 CPallini 163
4 Aarti Meswania 158
0 Sergey Alexandrovich Kryukov 10,129
1 OriginalGriff 7,749
2 CPallini 4,181
3 Rohan Leuva 3,482
4 Maciej Los 2,999


Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 8 May 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid