当前位置: 首页>>代码示例>>C++>>正文


C++ TLocale::FormatCurrency方法代码示例

本文整理汇总了C++中TLocale::FormatCurrency方法的典型用法代码示例。如果您正苦于以下问题:C++ TLocale::FormatCurrency方法的具体用法?C++ TLocale::FormatCurrency怎么用?C++ TLocale::FormatCurrency使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TLocale的用法示例。


在下文中一共展示了TLocale::FormatCurrency方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: HandleCommandL

// -----------------------------------------------------------------------------
// CLocalizationAppUi::HandleCommandL()
// Takes care of command handling.
// -----------------------------------------------------------------------------
//
void CLocalizationAppUi::HandleCommandL( TInt aCommand )
    {
    switch( aCommand )
        {
        case EEikCmdExit:
        case EAknSoftkeyExit:
            Exit();
            break;

		// Number
        case ELocalizationCommandNumber:
            {
				// buffer for localized text
				TBuf<50> myBuf;
				
				// Amount to show
				TReal myAmount = 1234.567;
				
				// Real number formatter, initialized with system's current locale settings
				TRealFormat myFormat;

				// Format real with current locales decimal separator setting
				myBuf.AppendNum(myAmount, myFormat);
				
				// Show formatted text
            	CAknInformationNote* informationNote = new ( ELeave ) CAknInformationNote;
	            informationNote->ExecuteLD( myBuf );
            }
            break;
		
		// Currency
		case ELocalizationCommandCurrency:
			{
				// locale is initialized with system's current locale settings
				TLocale myLocale;
				
				// buffer for localized text
				TBuf<50> myBuf;

				// amount is integer, but it is treated as last two digits
				// were decimal digits e.g. 1249 = 12.49, 2 = 0.02 ...
				TInt myAmount = 123456789;
				
				// Format currency according to current locale settings
				myLocale.FormatCurrency(myBuf, myAmount);

				// Show formatted text				
            	CAknInformationNote* informationNote = new ( ELeave ) CAknInformationNote;
	            informationNote->ExecuteLD( myBuf );
			}
			break;
			
		// Date
		case ELocalizationCommandDate:
			{
				// buffer for localized text
				TBuf<50> myBuf;
				
				// Object for datetime data
				TTime myDate;
				
				// Set current datetime to object
				myDate.HomeTime();
				
				// Format date according to current locale settings
				// Format string is universal, so that whatever the locale is,
				// date is always formatted correctly
				myDate.FormatL(myBuf, _L("%/0%1%/1%2%/2%3%/3%X"));
				
				// Show formatted text				
            	CAknInformationNote* informationNote = new ( ELeave ) CAknInformationNote;
	            informationNote->ExecuteLD( myBuf );
			}
			break;
			
		// Time
		case ELocalizationCommandTime:
			{
				// buffer for localized text
				TBuf<50> myBuf;
				
				// Object for datetime data
				TTime myTime;
				
				// Set current datetime to object
				myTime.HomeTime();

				// Format time to current locale
				// Format string is universal, so that whatever the locale is,
				// time is always formatted correctly
				myTime.FormatL(myBuf, _L("%-B%:0%J%:1%T%:2%S%:3%+B"));
				
				// Show formatted text			
            	CAknInformationNote* informationNote = new ( ELeave ) CAknInformationNote;
	            informationNote->ExecuteLD( myBuf );
//.........这里部分代码省略.........
开发者ID:fedor4ever,项目名称:packaging,代码行数:101,代码来源:localizationappui.cpp


注:本文中的TLocale::FormatCurrency方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。