2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file FLclNumberFormatter.h
19 * @brief This is the header file for the %NumberFormatter class.
21 * This header file contains the declarations of the %NumberFormatter class.
24 #ifndef _FLCL_NUMBER_FORMATTER_H_
25 #define _FLCL_NUMBER_FORMATTER_H_
27 #include <FLclLocale.h>
28 #include <FLclCurrency.h>
30 namespace Tizen { namespace Locales
34 * @class NumberFormatter
35 * @brief This class provides methods for formatting numbers.
39 * 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.
41 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/locales/num_formatter.htm">Number Formatters</a>.
43 * The following example demonstrates how to use the %NumberFormatter class.
50 using namespace Tizen::Base;
51 using namespace Tizen::Locales;
54 LocaleApp::NumberFormatterExample(void)
57 Locale koreaLoc(LANGUAGE_KOR, COUNTRY_KR);
59 // Get number formatter
60 NumberFormatter* pNumberFormatter = NumberFormatter::CreateNumberFormatterN(koreaLoc);
62 String formattedString;
64 // Format number with number formatter
65 double num = 345987.246;
66 pNumberFormatter->Format(num, formattedString);
68 // Get currency formatter
69 NumberFormatter* pCurrencyFormatter = NumberFormatter::CreateCurrencyFormatterN(koreaLoc);
71 // Format number with currency formatter
73 pCurrencyFormatter->Format(num, formattedString);
75 // Get percent formatter
76 NumberFormatter* pPercentFormatter = NumberFormatter::CreatePercentFormatterN(koreaLoc);
78 // Format number with percent formatter
80 pPercentFormatter->Format(num, formattedString);
82 delete pNumberFormatter;
83 delete pCurrencyFormatter;
84 delete pPercentFormatter;
90 class _OSP_EXPORT_ NumberFormatter
91 : public Tizen::Base::Object
95 * This is the destructor for this class. @n
96 * This destructor overrides Tizen::Base::Object::~Object().
100 virtual ~NumberFormatter(void);
104 * Creates a number formatter for the system locale.
108 * @return A pointer to the general number formatter for the default locale, @n
109 * else @c null if an error occurs
110 * @exception E_SUCCESS The method is successful.
111 * @exception E_OUT_OF_MEMORY The memory is insufficient.
112 * @exception E_UNSUPPORTED_OPERATION The system locale is not supported.
113 * @remarks The specific error code can be accessed using the GetLastResult() method.
115 static NumberFormatter* CreateNumberFormatterN(void);
119 * Creates a number formatter for the specified locale.
122 * @brief <i> [Compatibility] </i>
126 * @compatibility This method has compatibility issues with OSP compatible applications. @n
127 * For more information, see @ref CompNumberFormatterCreateNumberFormatterNPage "here".
130 * @return A pointer to a general number formatter for the specified @c locale, @n
131 * else @c null if an error occurs
132 * @param[in] locale An instance of Locale
133 * @exception E_SUCCESS The method is successful.
134 * @exception E_OUT_OF_MEMORY The memory is insufficient.
135 * @exception E_INVALID_ARG The specified @c locale is invalid.
136 * @remarks The specific error code can be accessed using the GetLastResult() method.
138 static NumberFormatter* CreateNumberFormatterN(const Locale& locale);
142 * @page CompNumberFormatterCreateNumberFormatterNPage Compatibility for CreateNumberFormatterN()
143 * @section CompNumberFormatterCreateNumberFormatterNIssueSection Issues
144 * Implementation of this method in OSP compatible applications has the following issue: @n
145 * -# The method returns E_UNSUPPORTED_OPERATION if the @c locale is invalid.
147 * @section CompNumberFormatterCreateNumberFormatterNSolutionSection Resolutions
148 * This issue has been resolved in Tizen.
149 * @par When working in Tizen:
150 * -# The method returns E_INVALID_ARG if the @c locale is invalid.
155 * Creates a currency formatter for the default locale.
159 * @return A pointer to a currency formatter for the default locale, @n
160 * else @c null if an error occurs
161 * @exception E_SUCCESS The method is successful.
162 * @exception E_OUT_OF_MEMORY The memory is insufficient.
163 * @exception E_UNSUPPORTED_OPERATION The system locale is not supported.
164 * @remarks The specific error code can be accessed using the GetLastResult() method.
166 static NumberFormatter* CreateCurrencyFormatterN(void);
170 * Creates a currency formatter for the specified @c locale.
173 * @brief <i> [Compatibility] </i>
177 * @compatibility This method has compatibility issues with OSP compatible applications. @n
178 * For more information, see @ref CompNumberFormatterCreateCurrencyFormatterNPage "here".
181 * @return A pointer to a currency formatter for the specified @c locale, @n
182 * else @c null if an error occurs
183 * @param[in] locale An instance of Locale
184 * @exception E_SUCCESS The method is successful.
185 * @exception E_OUT_OF_MEMORY The memory is insufficient.
186 * @exception E_INVALID_ARG The specified @c locale is invalid.
187 * @remarks The specific error code can be accessed using the GetLastResult() method.
189 static NumberFormatter* CreateCurrencyFormatterN(const Locale& locale);
193 * @page CompNumberFormatterCreateCurrencyFormatterNPage Compatibility for CreateCurrencyFormatterN()
194 * @section CompNumberFormatterCreateCurrencyFormatterNIssueSection Issues
195 * Implementation of this method in OSP compatible applications has the following issue: @n
196 * -# The method returns E_UNSUPPORTED_OPERATION if the @c locale is invalid.
198 * @section CompNumberFormatterCreateCurrencyFormatterNSolutionSection Resolutions
199 * This issue has been resolved in Tizen.
200 * @par When working in Tizen:
201 * -# The method returns E_INVALID_ARG if the @c locale is invalid.
206 * Creates a percentage formatter for the system locale.
210 * @return A pointer to a percentage formatter for the default locale, @n
211 * else @c null if an error occurs
212 * @exception E_SUCCESS The method is successful.
213 * @exception E_OUT_OF_MEMORY The memory is insufficient.
214 * @exception E_UNSUPPORTED_OPERATION The system locale is not supported.
215 * @remarks The specific error code can be accessed using the GetLastResult() method.
217 static NumberFormatter* CreatePercentFormatterN(void);
221 * Creates a percentage formatter for the specified @c locale.
224 * @brief <i> [Compatibility] </i>
228 * @compatibility This method has compatibility issues with OSP compatible applications. @n
229 * For more information, see @ref CompNumberFormatterCreatePercentFormatterNPage "here".
232 * @return A pointer to a percentage formatter for the specified @c locale, @n
233 * else @c null if an error occurs
234 * @param[in] locale An instance of Locale
235 * @exception E_SUCCESS The method is successful.
236 * @exception E_OUT_OF_MEMORY The memory is insufficient.
237 * @exception E_INVALID_ARG The specified @c locale is invalid.
238 * @remarks The specific error code can be accessed using the GetLastResult() method.
240 static NumberFormatter* CreatePercentFormatterN(const Locale& locale);
244 * @page CompNumberFormatterCreatePercentFormatterNPage Compatibility for CreatePercentFormatterN()
245 * @section CompNumberFormatterCreatePercentFormatterNIssueSection Issues
246 * Implementation of this method in OSP compatible applications has the following issue: @n
247 * -# The method returns E_UNSUPPORTED_OPERATION if the @c locale is invalid.
249 * @section CompNumberFormatterCreatePercentFormatterNSolutionSection Resolutions
250 * This issue has been resolved in Tizen.
251 * @par When working in Tizen:
252 * -# The method returns E_INVALID_ARG if the @c locale is invalid.
259 * Formats a number of type Tizen::Base::Long to type Tizen::Base::String and appends the resulting string to a buffer.
263 * @return An error code
264 * @param[in] number The number of type Tizen::Base::Long to format
265 * @param[out] str The string to append to the resultant string
266 * @exception E_SUCCESS The method is successful.
268 virtual result Format(long number, Tizen::Base::String& str) const;
272 * Formats a number of type Tizen::Base::Double to type Tizen::Base::String and appends the resulting string to a buffer.
276 * @return An error code
277 * @param[in] number The number of type Tizen::Base::Double to format
278 * @param[out] str The string to append to the resultant string
279 * @exception E_SUCCESS The method is successful.
281 virtual result Format(double number, Tizen::Base::String& str) const;
285 * Gets the currency used by the current number format when formatting currency values.
289 * @return A pointer to an instance of Currency
290 * @remarks The initial value is derived in a locale dependent way. @n
291 * The returned value may be @c null if no valid currency is determined
292 * or no currency has been set using the SetCurrency() method.
295 virtual const Currency* GetCurrency(void) const;
299 * Sets the currency used by the current number format when formatting currency values.
303 * @param[in] currency The new currency to use by the current number format
304 * @remarks This does not update the minimum or maximum number of fractional digits used by the number format.
307 virtual void SetCurrency(const Currency& currency);
311 * Gets the maximum number of digits allowed in the integer portion of a number.
315 * @return An integer value representing the maximum number of digits allowed in the integer portion of a number
316 * @see SetMaxIntegerDigits()
318 virtual int GetMaxIntegerDigits(void) const;
322 * Sets the maximum number of digits allowed in the integer portion of a number.
326 * @param[in] newValue The maximum number of integer digits allowed in the integer portion of a number, @n
327 * If less than zero, @c 0 is used.
328 * @remarks The maximum integer digits must be greater than or equal to the minimum integer digits.
329 * If the new value for the maximum integer digits is less than the current value of the minimum integer digits,
330 * the minimum integer digits are also set to the new value.
331 * @see GetMaxIntegerDigits()
333 virtual void SetMaxIntegerDigits(int newValue);
337 * Gets the minimum number of digits allowed in the integer portion of a number.
341 * @return An integer value representing the minimum number of digits allowed in the integer portion of a number
342 * @see SetMinIntegerDigits()
344 virtual int GetMinIntegerDigits(void) const;
348 * Sets the minimum number of digits allowed in the integer portion of a number.
352 * @param[in] newValue The minimum number of integer digits allowed in the integer portion of a number @n
353 * If less than zero, @c 0 is used.
354 * @remarks The minimum integer digits must be less than or equal to the maximum integer digits.
355 * If the new value for the minimum integer digits exceeds the current value of the maximum integer digits,
356 * the maximum integer digits are also set to the new value.
357 * @see GetMinIntegerDigits()
359 virtual void SetMinIntegerDigits(int newValue);
363 * Gets the maximum number of digits allowed in the fractional portion of a number.
367 * @return An integer value representing the maximum number of digits allowed in the fractional portion of a number
368 * @see SetMaxFractionDigits()
370 virtual int GetMaxFractionDigits(void) const;
374 * Sets the maximum number of digits allowed in the fractional portion of a number.
378 * @param[in] newValue The maximum number of fractional digits allowed in the fractional portion of a number @n
379 * If less than zero, @c 0 is used.
380 * @remarks The maximum fractional digits must be greater than or equal to the minimum fractional digits.
381 * If the new value for the maximum fractional digits is less than the current value of the minimum fractional digits,
382 * the minimum fractional digits are also set to the new value.
383 * @see GetMaxFractionDigits()
385 virtual void SetMaxFractionDigits(int newValue);
389 * Gets the minimum number of digits allowed in the fractional portion of a number.
393 * @return An integer value representing the minimum number of digits allowed in the fractional portion of a number
394 * @see SetMinFractionDigits()
396 virtual int GetMinFractionDigits(void) const;
400 * Sets the minimum number of digits allowed in the fractional portion of a number.
404 * @param[in] newValue The minimum number of fractional digits allowed in the fractional portion of a number @n
405 * If less than zero, @c 0 is used.
406 * @remarks The minimum fractional digits must be less than or equal to the maximum fractional digits.
407 * If the new value for the minimum fractional digits exceeds the current value of the maximum fraction digits,
408 * the maximum fraction digits are also set to the new value.
409 * @see GetMinFractionDigits()
411 virtual void SetMinFractionDigits(int newValue);
415 * Checks whether the grouping is used in the current instance of %NumberFormatter.
419 * @return @c true if grouping is used in the current instance of %NumberFormatter, @n
421 * @remarks For example, in the English locale, with grouping on, the number 1234567
422 * might be formatted as "1,234,567".
423 * The grouping separator as well as the size of each group is locale dependent
424 * and is determined by subclasses of %NumberFormatter.
425 * @see SetGroupingUsed()
427 virtual bool IsGroupingUsed(void) const;
431 * Sets the current instance of %NumberFormatter to use or not to use grouping.
435 * @param[in] newValue Set to @c true if grouping is used in the current formatter, @n
437 * @see IsGroupingUsed()
439 virtual void SetGroupingUsed(bool newValue);
443 * Applies the specified pattern to the current instance of %NumberFormatter.
447 * @return An error code
448 * @param[in] pattern The new pattern
449 * @param[in] localized The localization On/Off flag @n
450 * Set to @c true if the pattern is applied with the localized symbols, @n
452 * @exception E_SUCCESS The method is successful.
453 * @exception E_INVALID_ARG The specified @c pattern is invalid or its length is @c 0.
455 result ApplyPattern(const Tizen::Base::String& pattern, bool localized);
459 * Gets the positive prefix of the current instance of %NumberFormatter.
463 * @return The positive prefix of the current %NumberFormatter instance
464 * @remarks For example: +123, $123, sFr123.
465 * @see SetPositivePrefix()
467 Tizen::Base::String GetPositivePrefix(void) const;
471 * Sets a new value for the positive prefix of the current instance of %NumberFormatter.
475 * @param[in] newValue The new positive prefix
476 * @see GetPositivePrefix()
478 void SetPositivePrefix(const Tizen::Base::String& newValue);
482 * Gets the negative prefix of the current instance of %NumberFormatter.
486 * @return The negative prefix of the current %NumberFormatter instance
487 * @remarks For example: -123, $123 (with negative prefix), sFr-123
488 * @see SetNegativePrefix()
490 Tizen::Base::String GetNegativePrefix(void) const;
494 * Sets a new value for the negative prefix of the current instance of %NumberFormatter.
498 * @param[in] newValue The new negative prefix
499 * @see GetNegativePrefix()
501 void SetNegativePrefix(const Tizen::Base::String& newValue);
505 * Gets the positive suffix of the current instance of %NumberFormatter.
509 * @return The positive suffix of the current %NumberFormatter instance
510 * @remarks For example: 123%
511 * @see SetPositiveSuffix()
513 Tizen::Base::String GetPositiveSuffix(void) const;
517 * Sets a new value for the positive suffix of the current instance of %NumberFormatter.
521 * @param[in] newValue The new positive suffix
522 * @see GetPositiveSuffix()
524 void SetPositiveSuffix(const Tizen::Base::String& newValue);
528 * Gets the negative suffix of the current instance of %NumberFormatter.
532 * @return The negative suffix of the current %NumberFormatter instance
533 * @remarks For example: -123%, $123 (with negative suffix)
534 * @see SetNegativeSuffix()
536 Tizen::Base::String GetNegativeSuffix(void) const;
540 * Sets a new value for the negative suffix of the current instance of %NumberFormatter.
544 * @param[in] newValue The new negative suffix
545 * @see GetNegativeSuffix()
547 void SetNegativeSuffix(const Tizen::Base::String& newValue);
551 * Gets the multiplier for use in percent, per mill, and so on.
555 * @return An integer value representing the multiplier
556 * @remarks For example: with 100, 1.23 -> "123", and "123" -> 1.23
557 * @see SetMultiplier()
559 int GetMultiplier(void) const;
563 * Sets a new value for the multiplier for use in percent, per mill, and so on.
567 * @param[in] newValue The new value for the multiplier
568 * @exception E_SUCCESS The method is successful.
569 * @exception E_INVALID_ARG The specified input parameter is invalid.
570 * @remarks For example, in percentage, set the suffixes to have "%" and the multiplier to be 100.
571 * @see GetMultiplier()
573 result SetMultiplier(int newValue);
577 * Gets the grouping size.
581 * @return An integer value representing the grouping size
582 * @remarks Grouping size is the number of digits between grouping separators in the integer portion of a number. @n
583 * For example, in the number "123,456.78", the grouping size is 3.
584 * @see SetGroupingSize()
585 * @see IsGroupingUsed()
587 int GetGroupingSize(void) const;
591 * Sets a new value for the grouping size.
595 * @param[in] newValue The new value for the grouping size
596 * @exception E_SUCCESS The method is successful.
597 * @exception E_INVALID_ARG The specified input parameter is invalid.
598 * @see GetGroupingSize()
599 * @see SetGroupingUsed()
601 result SetGroupingSize(int newValue);
605 * Checks whether the decimal separator is always shown.
609 * @return @c true if the decimal separator is always shown, @n
611 * @remarks For example: ON: 12345 -> 12345.; OFF: 12345 -> 12345
612 * @see SetDecimalSeparatorAlwaysShown()
614 bool IsDecimalSeparatorAlwaysShown(void) const;
618 * Sets the behavior of the decimal separator. @n
619 * The decimal separator can be set to always appear using this method.
623 * @param[in] newValue Set to @c true if the decimal separator is always shown, @n
625 * @see IsDecimalSeparatorAlwaysShown()
627 void SetDecimalSeparatorAlwaysShown(bool newValue);
631 * Checks whether the positive sign is always shown.
635 * @return @c true if the positive sign is always shown, @n
637 * @remarks For example: ON: 12345 -> +12345.; OFF: 12345 -> 12345.
638 * @see SetPositiveSignAlwaysShown()
640 bool IsPositiveSignAlwaysShown(void) const;
644 * Sets the behavior of the plus sign. @n
645 * The plus sign can be set to always appear using this method.
649 * @param[in] newValue Set to @c true if the plus sign is always shown, @n
651 * @see IsPositiveSignAlwaysShown()
653 void SetPositiveSignAlwaysShown(bool newValue);
658 * This default constructor is intentionally declared as private so that only the platform can create an instance.
660 NumberFormatter(void);
663 * The implementation of this copy constructor is intentionally blank and declared as private to
664 * prohibit copying of objects.
666 NumberFormatter(const NumberFormatter& numberFormatter);
669 * The implementation of this copy assignment operator is intentionally blank and declared as private
670 * to prohibit copying of objects.
672 NumberFormatter& operator =(const NumberFormatter& numberFormatter);
674 friend class _NumberFormatterImpl;
675 class _NumberFormatterImpl* __pNumberFormatterImpl;
677 }; // NumberFormatter
681 #endif //_FLCL_NUMBER_FORMATTER_H_