00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "CommonFramework.h"
00017
00018
00019 void printCurrency();
00020 void formatCurrency(TDes &aBuffer, TReal currencyAmount);
00021
00022
00023 LOCAL_C void doExampleL()
00024 {
00025
00026
00027
00028
00029
00030 TLocale locale;
00031 TCurrencySymbol currencySymbol;
00032 currencySymbol.Set();
00033 locale.SetCurrencySymbolPosition(ELocaleBefore);
00034 locale.SetCurrencySpaceBetween(EFalse);
00035 locale.SetNegativeCurrencyFormat(TLocale::ELeadingMinusSign);
00036 locale.SetCurrencyDecimalPlaces(2);
00037 locale.SetCurrencyTriadsAllowed(ETrue);
00038 locale.SetThousandsSeparator(',');
00039 locale.SetDecimalSeparator('.');
00040 locale.Set();
00041 printCurrency();
00042 }
00043
00044 void printCurrency()
00045 {
00046 TBuf<30> aBuffer;
00047 aBuffer.Zero();
00048 TReal currencyAmount=-12345678.119;
00049 formatCurrency(aBuffer, currencyAmount);
00050 _LIT(KFormat1,"Currency value is: %S\n");
00051 console->Printf(KFormat1,&aBuffer);
00052 }
00053
00054 void formatCurrency(TDes &aBuffer, TReal currencyAmount)
00055 {
00056
00057
00058
00059 TLocale locale;
00060 TRealFormat realFormat;
00061
00062
00063
00064
00065
00066 realFormat.iType=KRealFormatFixed;
00067
00068 realFormat.iWidth=30;
00069
00070 realFormat.iPlaces=locale.CurrencyDecimalPlaces();
00071 realFormat.iPoint=locale.DecimalSeparator();
00072 realFormat.iTriad=locale.ThousandsSeparator();
00073 realFormat.iTriLen=(locale.CurrencyTriadsAllowed() ? 1 : 0);
00074 TCurrencySymbol symbol;
00075
00076
00077 _LIT(KTxtOpenBra,"(");
00078 _LIT(KTxtSpace," ");
00079 _LIT(KTxtCloseBra,")");
00080 _LIT(KTxtMinusSign,"-");
00081
00082
00083
00084
00085
00086
00087
00088
00089 TUint currencySymbolAtFront;
00090 TUint spaceBetweenSymbolAndValue;
00091
00092
00093
00094
00095 currencySymbolAtFront = ((locale.CurrencySymbolPosition()==ELocaleBefore) ? 0x01 : 0x00);
00096 spaceBetweenSymbolAndValue = (locale.CurrencySpaceBetween() ? 0x01 : 0x00);
00097
00098
00099
00100
00101 if (currencyAmount<0)
00102 {
00103
00104
00105 currencySymbolAtFront ^= (locale.NegativeCurrencySymbolOpposite() ? 0x01 : 0x00);
00106
00107
00108
00109 if (spaceBetweenSymbolAndValue && locale.NegativeLoseSpace())
00110 {
00111 spaceBetweenSymbolAndValue = 0x00;
00112 }
00113
00114
00115 switch (locale.NegativeCurrencyFormat())
00116 {
00117 case TLocale::ELeadingMinusSign :
00118 {
00119 aBuffer.Append(KTxtMinusSign);
00120 if (currencySymbolAtFront)
00121 {
00122 aBuffer.Append(symbol);
00123 if (spaceBetweenSymbolAndValue)
00124 {
00125 aBuffer.Append(KTxtSpace);
00126 }
00127 aBuffer.AppendNum(-currencyAmount,realFormat);
00128 }
00129 else
00130 {
00131 aBuffer.AppendNum(-currencyAmount,realFormat);
00132 if (spaceBetweenSymbolAndValue)
00133 {
00134 aBuffer.Append(KTxtSpace);
00135 }
00136 aBuffer.Append(symbol);
00137 }
00138 break;
00139 }
00140
00141 case TLocale::ETrailingMinusSign :
00142 {
00143 if (currencySymbolAtFront)
00144 {
00145 aBuffer.Append(symbol);
00146 if (spaceBetweenSymbolAndValue)
00147 {
00148 aBuffer.Append(KTxtSpace);
00149 }
00150 aBuffer.AppendNum(-currencyAmount,realFormat);
00151 aBuffer.Append(KTxtMinusSign);
00152 }
00153 else
00154 {
00155 aBuffer.AppendNum(-currencyAmount,realFormat);
00156 aBuffer.Append(KTxtMinusSign);
00157 if (spaceBetweenSymbolAndValue)
00158 {
00159 aBuffer.Append(KTxtSpace);
00160 }
00161 aBuffer.Append(symbol);
00162 }
00163 break;
00164 }
00165
00166 case TLocale::EInterveningMinusSign :
00167 {
00168 if (currencySymbolAtFront)
00169 {
00170 aBuffer.Append(symbol);
00171 if (spaceBetweenSymbolAndValue)
00172 {
00173 aBuffer.Append(KTxtSpace);
00174 }
00175 aBuffer.AppendNum(currencyAmount,realFormat);
00176 }
00177 else
00178 {
00179 aBuffer.AppendNum(currencyAmount,realFormat);
00180 if (spaceBetweenSymbolAndValue)
00181 {
00182 aBuffer.Append(KTxtSpace);
00183 }
00184 aBuffer.Append(symbol);
00185 }
00186 break;
00187 }
00188
00189 default :
00190 {
00191 aBuffer.Append(KTxtOpenBra);
00192 if (currencySymbolAtFront)
00193 {
00194 aBuffer.Append(symbol);
00195 if (spaceBetweenSymbolAndValue)
00196 {
00197 aBuffer.Append(KTxtSpace);
00198 }
00199 aBuffer.AppendNum(-currencyAmount,realFormat);
00200 }
00201 else
00202 {
00203 aBuffer.AppendNum(-currencyAmount,realFormat);
00204 if (spaceBetweenSymbolAndValue)
00205 {
00206 aBuffer.Append(KTxtSpace);
00207 }
00208 aBuffer.Append(symbol);
00209 }
00210 aBuffer.Append(KTxtCloseBra);
00211 break;
00212 }
00213
00214 }
00215 }
00216
00217
00218
00219
00220 else
00221 {
00222 if (currencySymbolAtFront)
00223 {
00224 aBuffer.Append(symbol);
00225 if (spaceBetweenSymbolAndValue)
00226 {
00227 aBuffer.Append(KTxtSpace);
00228 }
00229 aBuffer.AppendNum(currencyAmount,realFormat);
00230 }
00231 else
00232 {
00233 aBuffer.AppendNum(currencyAmount,realFormat);
00234 if (spaceBetweenSymbolAndValue)
00235 {
00236 aBuffer.Append(KTxtSpace);
00237 }
00238 aBuffer.Append(symbol);
00239 }
00240 }
00241
00242 }