mfc >> Formating CString

by Adrian Kole » Tue, 25 Nov 2003 00:00:07 GMT

If you use %g, numbers will be output in a compact format when it can and,
when numbers are very small or large, in scientific notation otherwise.

Adrian

"Lionel" < XXXX@XXXXX.COM > wrote in message
news:516001c3b2a3$3703b8b0$ XXXX@XXXXX.COM ...
> I'm using the CStrings' Format function to convert a float
> to a CString as follows:
>
> ValueString.Format("%#.2f",FloatValue);//Convert value.
>
> Sometimes my numbers are very large or small and in these
> cases I would like to use scientific notation. Is there a
> way to convert the floats to scientific notation CStrings?




mfc >> Formating CString

by Ali R. » Tue, 25 Nov 2003 00:08:13 GMT


ValueString.Format("%.2e",FloatValue); will give you scientific notation,
but it won't do the normal notation. Are you open to using the c++ iostream
routines?

stringstream str;

str << FloatValue;

That one does it automatically.

Ali R.








mfc >> Formating CString

by anonymous » Tue, 25 Nov 2003 00:24:22 GMT

Thanks for the reply. I will not be using the c++
iostream. Actually, I'm converting to CString and then
drawing to screen GDI+.



scientific notation,
using the c++ iostream
message

float
these
a
CStrings?


Formating CString

by Adrian Kole » Tue, 25 Nov 2003 00:35:07 GMT

You're welcome. Looking at the help (the link at
ms-help://MS.MSDNVS/vclib/html/_crt_printf_type_field_characters.htm#_crt_ta
ble_r..3 in Visual Studio), I don't see any reference in that table for
specifying the range for that. Sorry!








Similar Threads

1. CString.FormatMessage and CString.Format difference

2. CString link error in VC7 with MFC extersion dll which export functions using CString as parameter

3. CString.FormatMessage and CString.Format difference

4. 'CMap' of 'CString' to 'CString'

Hello!

I'm trying to create a dictionary with both key and value of type
'CString'. I declare the object of 'CMap' so it is as closer to
std::map, as possible:

CMap<CString, const CString&, CString, const CString&> m_appLangs;

and semantically it's like this:

std::map<std::string, std::string> m_appLangs;

But it seems 'CMap' is not realized as an RB-tree, I guess it must be
realized through hash table. The problem is when I make the above
declaration, my source file refuse to compile. Here is the simplified
error message:

cannot convert from 'const CString' to 'DWORD_PTR'
see reference to function template instantiation 'UINT
HashKey<ARG_KEY>(ARG_KEY)' being compiled with
[ARG_KEY=const CString &]

Here is the code of 'HashKey' function from "afxtempl.h":

template<class ARG_KEY>
AFX_INLINE UINT AFXAPI HashKey(ARG_KEY key)
{
	// default identity hash - works for most primitive values
	return (DWORD)(((DWORD_PTR)key)>>4);
}

And what does it mean? Can't I create a map of string to string just
because there is no conversion from 'CString' to 'DWORD_PTR'? I think/
hope I'm wrong. Would you please show me my mistake?

Thanks in advance
Martin

5. CString hex value to CString decimal value

6. Unable to convert from ATL::CString to vector<CString>::iterator

Hi Guys,

I am going through the lengthy process of upgrading from a VS6 project to 
VS2005.
The only issue I am left with is that I cannot work how to convert from a 
CString as part of an array to a vector iterator.

The code is as follows

vector<CString>::iterator ii = 
vector<CString>&(m_vsOverallAgentRetrievalQueueNames[i]);

and the error message is as follows

error C2440: 'initializing' : cannot convert from 
'ATL::CStringT<BaseType,StringTraits> *' to 
'std::_Vector_iterator<_Ty,_Alloc>'

Can anyone help at all?

Regards

Tony 

7. Array of CString s vs. CString Array

8. Locales and CString::MakeUpper() and CString::CollateNoCase()

I recently discovered that when running my Unicode application on an 
English XP system with my locales all set to English (US), the 
CString::MakeUpper() function did not convert a Russian text string from 
mixed case (  ) to uppercase (  ). The 
function that does the actual conversion is _wcsupr_s(). After some 
digging, I eventually discovered that the conversion is dependent on the 
locale set using the CRT setLocale() function. When I set the locale 
using setLocale(LC_ALL, ".1251"), the CString::MakeUpper() function 
worked as expected.

This seems wrong to me. If I have Unicode text in many different 
languages, I cannot know which code page to set to make the MakeUpper() 
function work. One reason for switching to Unicode is that we don't want 
to worry about code pages.

The CString::CollateNoCase() works similarly. If I call this function 
with the two Russian text strings listed above, the return is non-zero 
unless I first set the locale to use code page 1251.

Why does CStringW::MakeUpper() use the locale dependent _wcsupr_s() 
function rather than the CharUpperBuff() function, which works 
correctly? At this point, it looks like my only option is to find all 
places where we use CollateNoCase(), MakeUpper(), and MakeLower() and 
replace them with our own functions to do these tasks. Am I missing 
something? Does anyone have an idea for a better solution?