⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 numericformat.cpp

📁 基于WINDOWS mobile 的用于创建一个窗体和自定义试图的工程
💻 CPP
字号:

#include "stdafx.h"

#include "NumericFormat.h"


// Format
//
//		Fast formats an integer
//
TCHAR* Format(int i, TCHAR *pBuf, size_t ccBuf, int nZeroPad)
{
	TCHAR*	psz	=	pBuf + ccBuf - 1;	// Set psz to last char
	int		ii	=	i < 0 ? -i : i;
    
	*psz = 0;							// Set terminating null
	do
	{
		unsigned    lsd = ii % 10;       // Get least significant
										// digit
		ii /= 10;                        // Prepare for next most
										// significant digit
		--psz;                          // Move back
		*psz = _T('0') + lsd;			// Place the digit
		--nZeroPad;						// Decrease the padding
	} while(ii != 0);

	//
	// Do any optional zero padding
	//
	for( ; nZeroPad > 0; --nZeroPad)
	{
		--psz;
		*psz = _T('0');
	}

	if(i < 0)
		*--psz = _T('-');

    return psz;
}


// Format
//
//		Fast formats an hex integer
//
TCHAR* FormatHex(DWORD i, TCHAR *pBuf, size_t ccBuf)
{
	TCHAR	szHex[] = _T("0123456789abcdef");
	TCHAR*	psz		=	pBuf + ccBuf - 1;	// Set psz to last char
    
	*psz = 0;								// Set terminating null
	do
	{
		unsigned    lsn = i & 0x0f;			// Get least significant
											// nibble
		i = i >> 4;							// Prepare for next most
											// significant digit
		--psz;								// Move back
		*psz = szHex[lsn];					// Place the digit
	} while(i != 0);

    return psz;
}


// Format
//
//		Formats a double
//
TCHAR *Format(double d, TCHAR *pBuf, size_t ccBuf, ENumberFormat format)
{
	TCHAR	wFmtRaw[32];
	int		nRet;

	wsprintf(wFmtRaw, _T("%f"), d);

	switch(format)
	{
	case fmtNumber:
		GetNumberFormat(LOCALE_USER_DEFAULT, NULL, wFmtRaw, NULL, pBuf, ccBuf);
		break;

	case fmtCurrency:
		GetCurrencyFormat(LOCALE_USER_DEFAULT, NULL, wFmtRaw, NULL, pBuf, ccBuf);
		break;

	case fmtInteger:
		{
			NUMBERFMT	nfmt = {0, 0, 0, _T(""), _T(""), 1};

			nRet = GetNumberFormat(LOCALE_USER_DEFAULT, NULL, wFmtRaw, &nfmt, pBuf, ccBuf);
		}
		break;
	}
	return pBuf;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -