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