2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FLclNumberFormatter.h
20 * @brief This is the header file for the %NumberFormatter class.
22 * This header file contains the declarations of the %NumberFormatter class.
25 #ifndef _FLCL_NUMBER_FORMATTER_H_
26 #define _FLCL_NUMBER_FORMATTER_H_
28 #include <FLclLocale.h>
29 #include <FLclCurrency.h>
31 namespace Tizen { namespace Locales
35 * @class NumberFormatter
36 * @brief This class provides methods for formatting numbers.
40 * The %NumberFormatter class is used to format all number formats, including decimal and real numbers, currency, and percentage for any locale. It also provides methods to determine the locales that have number formats and their names. You can write codes completely independent of the locale conventions for decimal points, thousand separators as well as of the specific decimal digits used or whether the number format is a decimal. A normal decimal number can also be displayed as a currency or as a percentage.
42 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/locales/num_formatter.htm">Number Formatters</a>.
44 * The following example demonstrates how to use the %NumberFormatter class.
51 using namespace Tizen::Base;
52 using namespace Tizen::Locales;
55 LocaleApp::NumberFormatterExample(void)
58 Locale koreaLoc(LANGUAGE_KOR, COUNTRY_KR);
60 // Get number formatter
61 NumberFormatter* pNumberFormatter = NumberFormatter::CreateNumberFormatterN(koreaLoc);
63 String formattedString;
65 // Format number with number formatter
66 double num = 345987.246;
67 pNumberFormatter->Format(num, formattedString);
69 // Get currency formatter
70 NumberFormatter* pCurrencyFormatter = NumberFormatter::CreateCurrencyFormatterN(koreaLoc);
72 // Format number with currency formatter
74 pCurrencyFormatter->Format(num, formattedString);
76 // Get percent formatter
77 NumberFormatter* pPercentFormatter = NumberFormatter::CreatePercentFormatterN(koreaLoc);
79 // Format number with percent formatter
81 pPercentFormatter->Format(num, formattedString);
83 delete pNumberFormatter;
84 delete pCurrencyFormatter;
85 delete pPercentFormatter;
91 class _OSP_EXPORT_ NumberFormatter
92 : public Tizen::Base::Object
96 * This is the destructor for this class. @n
97 * This destructor overrides Tizen::Base::Object::~Object().
101 virtual ~NumberFormatter(void);
105 * Creates a number formatter for the system locale.
109 * @return A pointer to the general number formatter for the default locale, @n
110 * else @c null if an error occurs
111 * @exception E_SUCCESS The method is successful.
112 * @exception E_OUT_OF_MEMORY The memory is insufficient.
113 * @exception E_UNSUPPORTED_OPERATION The system locale is not supported.
114 * @remarks The specific error code can be accessed using the GetLastResult() method.
116 static NumberFormatter* CreateNumberFormatterN(void);
120 * Creates a number formatter for the specified locale.
123 * @brief <i> [Compatibility] </i>
127 * @compatibility This method has compatibility issues with OSP compatible applications. @n
128 * For more information, see @ref CompNumberFormatterCreateNumberFormatterNPage "here".
131 * @return A pointer to a general number formatter for the specified @c locale, @n
132 * else @c null if an error occurs
133 * @param[in] locale An instance of Locale
134 * @exception E_SUCCESS The method is successful.
135 * @exception E_OUT_OF_MEMORY The memory is insufficient.
136 * @exception E_INVALID_ARG The specified @c locale is invalid.
137 * @remarks The specific error code can be accessed using the GetLastResult() method.
139 static NumberFormatter* CreateNumberFormatterN(const Locale& locale);
143 * @page CompNumberFormatterCreateNumberFormatterNPage Compatibility for CreateNumberFormatterN()
144 * @section CompNumberFormatterCreateNumberFormatterNIssueSection Issues
145 * Implementation of this method in OSP compatible applications has the following issue: @n
146 * -# The method returns E_UNSUPPORTED_OPERATION if the @c locale is invalid.
148 * @section CompNumberFormatterCreateNumberFormatterNSolutionSection Resolutions
149 * This issue has been resolved in Tizen.
150 * @par When working in Tizen:
151 * -# The method returns E_INVALID_ARG if the @c locale is invalid.
156 * Creates a currency formatter for the default locale.
160 * @return A pointer to a currency formatter for the default locale, @n
161 * else @c null if an error occurs
162 * @exception E_SUCCESS The method is successful.
163 * @exception E_OUT_OF_MEMORY The memory is insufficient.
164 * @exception E_UNSUPPORTED_OPERATION The system locale is not supported.
165 * @remarks The specific error code can be accessed using the GetLastResult() method.
167 static NumberFormatter* CreateCurrencyFormatterN(void);
171 * Creates a currency formatter for the specified @c locale.
174 * @brief <i> [Compatibility] </i>
178 * @compatibility This method has compatibility issues with OSP compatible applications. @n
179 * For more information, see @ref CompNumberFormatterCreateCurrencyFormatterNPage "here".
182 * @return A pointer to a currency formatter for the specified @c locale, @n
183 * else @c null if an error occurs
184 * @param[in] locale An instance of Locale
185 * @exception E_SUCCESS The method is successful.
186 * @exception E_OUT_OF_MEMORY The memory is insufficient.
187 * @exception E_INVALID_ARG The specified @c locale is invalid.
188 * @remarks The specific error code can be accessed using the GetLastResult() method.
190 static NumberFormatter* CreateCurrencyFormatterN(const Locale& locale);
194 * @page CompNumberFormatterCreateCurrencyFormatterNPage Compatibility for CreateCurrencyFormatterN()
195 * @section CompNumberFormatterCreateCurrencyFormatterNIssueSection Issues
196 * Implementation of this method in OSP compatible applications has the following issue: @n
197 * -# The method returns E_UNSUPPORTED_OPERATION if the @c locale is invalid.
199 * @section CompNumberFormatterCreateCurrencyFormatterNSolutionSection Resolutions
200 * This issue has been resolved in Tizen.
201 * @par When working in Tizen:
202 * -# The method returns E_INVALID_ARG if the @c locale is invalid.
207 * Creates a percentage formatter for the system locale.
211 * @return A pointer to a percentage formatter for the default locale, @n
212 * else @c null if an error occurs
213 * @exception E_SUCCESS The method is successful.
214 * @exception E_OUT_OF_MEMORY The memory is insufficient.
215 * @exception E_UNSUPPORTED_OPERATION The system locale is not supported.
216 * @remarks The specific error code can be accessed using the GetLastResult() method.
218 static NumberFormatter* CreatePercentFormatterN(void);
222 * Creates a percentage formatter for the specified @c locale.
225 * @brief <i> [Compatibility] </i>
229 * @compatibility This method has compatibility issues with OSP compatible applications. @n
230 * For more information, see @ref CompNumberFormatterCreatePercentFormatterNPage "here".
233 * @return A pointer to a percentage formatter for the specified @c locale, @n
234 * else @c null if an error occurs
235 * @param[in] locale An instance of Locale
236 * @exception E_SUCCESS The method is successful.
237 * @exception E_OUT_OF_MEMORY The memory is insufficient.
238 * @exception E_INVALID_ARG The specified @c locale is invalid.
239 * @remarks The specific error code can be accessed using the GetLastResult() method.
241 static NumberFormatter* CreatePercentFormatterN(const Locale& locale);
245 * @page CompNumberFormatterCreatePercentFormatterNPage Compatibility for CreatePercentFormatterN()
246 * @section CompNumberFormatterCreatePercentFormatterNIssueSection Issues
247 * Implementation of this method in OSP compatible applications has the following issue: @n
248 * -# The method returns E_UNSUPPORTED_OPERATION if the @c locale is invalid.
250 * @section CompNumberFormatterCreatePercentFormatterNSolutionSection Resolutions
251 * This issue has been resolved in Tizen.
252 * @par When working in Tizen:
253 * -# The method returns E_INVALID_ARG if the @c locale is invalid.
260 * Formats a number of type Tizen::Base::Long to type Tizen::Base::String and appends the resulting string to a buffer.
264 * @return An error code
265 * @param[in] number The number of type Tizen::Base::Long to format
266 * @param[out] str The string to append to the resultant string
267 * @exception E_SUCCESS The method is successful.
269 virtual result Format(long number, Tizen::Base::String& str) const;
273 * Formats a number of type Tizen::Base::Double to type Tizen::Base::String and appends the resulting string to a buffer.
277 * @return An error code
278 * @param[in] number The number of type Tizen::Base::Double to format
279 * @param[out] str The string to append to the resultant string
280 * @exception E_SUCCESS The method is successful.
282 virtual result Format(double number, Tizen::Base::String& str) const;
286 * Gets the currency used by the current number format when formatting currency values.
290 * @return A pointer to an instance of Currency
291 * @remarks The initial value is derived in a locale dependent way. @n
292 * The returned value may be @c null if no valid currency is determined
293 * or no currency has been set using the SetCurrency() method.
296 virtual const Currency* GetCurrency(void) const;
300 * Sets the currency used by the current number format when formatting currency values.
304 * @param[in] currency The new currency to use by the current number format
305 * @remarks This does not update the minimum or maximum number of fractional digits used by the number format.
308 virtual void SetCurrency(const Currency& currency);
312 * Gets the maximum number of digits allowed in the integer portion of a number.
316 * @return An integer value representing the maximum number of digits allowed in the integer portion of a number
317 * @see SetMaxIntegerDigits()
319 virtual int GetMaxIntegerDigits(void) const;
323 * Sets the maximum number of digits allowed in the integer portion of a number.
327 * @param[in] newValue The maximum number of integer digits allowed in the integer portion of a number, @n
328 * If less than zero, @c 0 is used.
329 * @remarks The maximum integer digits must be greater than or equal to the minimum integer digits.
330 * If the new value for the maximum integer digits is less than the current value of the minimum integer digits,
331 * the minimum integer digits are also set to the new value.
332 * @see GetMaxIntegerDigits()
334 virtual void SetMaxIntegerDigits(int newValue);
338 * Gets the minimum number of digits allowed in the integer portion of a number.
342 * @return An integer value representing the minimum number of digits allowed in the integer portion of a number
343 * @see SetMinIntegerDigits()
345 virtual int GetMinIntegerDigits(void) const;
349 * Sets the minimum number of digits allowed in the integer portion of a number.
353 * @param[in] newValue The minimum number of integer digits allowed in the integer portion of a number @n
354 * If less than zero, @c 0 is used.
355 * @remarks The minimum integer digits must be less than or equal to the maximum integer digits.
356 * If the new value for the minimum integer digits exceeds the current value of the maximum integer digits,
357 * the maximum integer digits are also set to the new value.
358 * @see GetMinIntegerDigits()
360 virtual void SetMinIntegerDigits(int newValue);
364 * Gets the maximum number of digits allowed in the fractional portion of a number.
368 * @return An integer value representing the maximum number of digits allowed in the fractional portion of a number
369 * @see SetMaxFractionDigits()
371 virtual int GetMaxFractionDigits(void) const;
375 * Sets the maximum number of digits allowed in the fractional portion of a number.
379 * @param[in] newValue The maximum number of fractional digits allowed in the fractional portion of a number @n
380 * If less than zero, @c 0 is used.
381 * @remarks The maximum fractional digits must be greater than or equal to the minimum fractional digits.
382 * If the new value for the maximum fractional digits is less than the current value of the minimum fractional digits,
383 * the minimum fractional digits are also set to the new value.
384 * @see GetMaxFractionDigits()
386 virtual void SetMaxFractionDigits(int newValue);
390 * Gets the minimum number of digits allowed in the fractional portion of a number.
394 * @return An integer value representing the minimum number of digits allowed in the fractional portion of a number
395 * @see SetMinFractionDigits()
397 virtual int GetMinFractionDigits(void) const;
401 * Sets the minimum number of digits allowed in the fractional portion of a number.
405 * @param[in] newValue The minimum number of fractional digits allowed in the fractional portion of a number @n
406 * If less than zero, @c 0 is used.
407 * @remarks The minimum fractional digits must be less than or equal to the maximum fractional digits.
408 * If the new value for the minimum fractional digits exceeds the current value of the maximum fraction digits,
409 * the maximum fraction digits are also set to the new value.
410 * @see GetMinFractionDigits()
412 virtual void SetMinFractionDigits(int newValue);
416 * Checks whether the grouping is used in the current instance of %NumberFormatter.
420 * @return @c true if grouping is used in the current instance of %NumberFormatter, @n
422 * @remarks For example, in the English locale, with grouping on, the number 1234567
423 * might be formatted as "1,234,567".
424 * The grouping separator as well as the size of each group is locale dependent
425 * and is determined by subclasses of %NumberFormatter.
426 * @see SetGroupingUsed()
428 virtual bool IsGroupingUsed(void) const;
432 * Sets the current instance of %NumberFormatter to use or not to use grouping.
436 * @param[in] newValue Set to @c true if grouping is used in the current formatter, @n
438 * @see IsGroupingUsed()
440 virtual void SetGroupingUsed(bool newValue);
444 * Applies the specified pattern to the current instance of %NumberFormatter.
448 * @return An error code
449 * @param[in] pattern The new pattern
450 * @param[in] localized The localization On/Off flag @n
451 * Set to @c true if the pattern is applied with the localized symbols, @n
453 * @exception E_SUCCESS The method is successful.
454 * @exception E_INVALID_ARG The specified @c pattern is invalid or its length is @c 0.
456 result ApplyPattern(const Tizen::Base::String& pattern, bool localized);
460 * Gets the positive prefix of the current instance of %NumberFormatter.
464 * @return The positive prefix of the current %NumberFormatter instance
465 * @remarks For example: +123, $123, sFr123.
466 * @see SetPositivePrefix()
468 Tizen::Base::String GetPositivePrefix(void) const;
472 * Sets a new value for the positive prefix of the current instance of %NumberFormatter.
476 * @param[in] newValue The new positive prefix
477 * @see GetPositivePrefix()
479 void SetPositivePrefix(const Tizen::Base::String& newValue);
483 * Gets the negative prefix of the current instance of %NumberFormatter.
487 * @return The negative prefix of the current %NumberFormatter instance
488 * @remarks For example: -123, $123 (with negative prefix), sFr-123
489 * @see SetNegativePrefix()
491 Tizen::Base::String GetNegativePrefix(void) const;
495 * Sets a new value for the negative prefix of the current instance of %NumberFormatter.
499 * @param[in] newValue The new negative prefix
500 * @see GetNegativePrefix()
502 void SetNegativePrefix(const Tizen::Base::String& newValue);
506 * Gets the positive suffix of the current instance of %NumberFormatter.
510 * @return The positive suffix of the current %NumberFormatter instance
511 * @remarks For example: 123%
512 * @see SetPositiveSuffix()
514 Tizen::Base::String GetPositiveSuffix(void) const;
518 * Sets a new value for the positive suffix of the current instance of %NumberFormatter.
522 * @param[in] newValue The new positive suffix
523 * @see GetPositiveSuffix()
525 void SetPositiveSuffix(const Tizen::Base::String& newValue);
529 * Gets the negative suffix of the current instance of %NumberFormatter.
533 * @return The negative suffix of the current %NumberFormatter instance
534 * @remarks For example: -123%, $123 (with negative suffix)
535 * @see SetNegativeSuffix()
537 Tizen::Base::String GetNegativeSuffix(void) const;
541 * Sets a new value for the negative suffix of the current instance of %NumberFormatter.
545 * @param[in] newValue The new negative suffix
546 * @see GetNegativeSuffix()
548 void SetNegativeSuffix(const Tizen::Base::String& newValue);
552 * Gets the multiplier for use in percent, per mill, and so on.
556 * @return An integer value representing the multiplier
557 * @remarks For example: with 100, 1.23 -> "123", and "123" -> 1.23
558 * @see SetMultiplier()
560 int GetMultiplier(void) const;
564 * Sets a new value for the multiplier for use in percent, per mill, and so on.
568 * @param[in] newValue The new value for the multiplier
569 * @exception E_SUCCESS The method is successful.
570 * @exception E_INVALID_ARG The specified input parameter is invalid.
571 * @remarks For example, in percentage, set the suffixes to have "%" and the multiplier to be 100.
572 * @see GetMultiplier()
574 result SetMultiplier(int newValue);
578 * Gets the grouping size.
582 * @return An integer value representing the grouping size
583 * @remarks Grouping size is the number of digits between grouping separators in the integer portion of a number. @n
584 * For example, in the number "123,456.78", the grouping size is 3.
585 * @see SetGroupingSize()
586 * @see IsGroupingUsed()
588 int GetGroupingSize(void) const;
592 * Sets a new value for the grouping size.
596 * @param[in] newValue The new value for the grouping size
597 * @exception E_SUCCESS The method is successful.
598 * @exception E_INVALID_ARG The specified input parameter is invalid.
599 * @see GetGroupingSize()
600 * @see SetGroupingUsed()
602 result SetGroupingSize(int newValue);
606 * Checks whether the decimal separator is always shown.
610 * @return @c true if the decimal separator is always shown, @n
612 * @remarks For example: ON: 12345 -> 12345.; OFF: 12345 -> 12345
613 * @see SetDecimalSeparatorAlwaysShown()
615 bool IsDecimalSeparatorAlwaysShown(void) const;
619 * Sets the behavior of the decimal separator. @n
620 * The decimal separator can be set to always appear using this method.
624 * @param[in] newValue Set to @c true if the decimal separator is always shown, @n
626 * @see IsDecimalSeparatorAlwaysShown()
628 void SetDecimalSeparatorAlwaysShown(bool newValue);
632 * Checks whether the positive sign is always shown.
636 * @return @c true if the positive sign is always shown, @n
638 * @remarks For example: ON: 12345 -> +12345.; OFF: 12345 -> 12345.
639 * @see SetPositiveSignAlwaysShown()
641 bool IsPositiveSignAlwaysShown(void) const;
645 * Sets the behavior of the plus sign. @n
646 * The plus sign can be set to always appear using this method.
650 * @param[in] newValue Set to @c true if the plus sign is always shown, @n
652 * @see IsPositiveSignAlwaysShown()
654 void SetPositiveSignAlwaysShown(bool newValue);
659 * This default constructor is intentionally declared as private so that only the platform can create an instance.
661 NumberFormatter(void);
664 * The implementation of this copy constructor is intentionally blank and declared as private to
665 * prohibit copying of objects.
667 NumberFormatter(const NumberFormatter& numberFormatter);
670 * The implementation of this copy assignment operator is intentionally blank and declared as private
671 * to prohibit copying of objects.
673 NumberFormatter& operator =(const NumberFormatter& numberFormatter);
675 friend class _NumberFormatterImpl;
676 class _NumberFormatterImpl* __pNumberFormatterImpl;
678 }; // NumberFormatter
682 #endif //_FLCL_NUMBER_FORMATTER_H_