String
Double::ToString(int precision) const
{
-//Dummy implementation to resolve build break
- return String(L"");
+ return Double::ToString(value, precision);
}
String
String
Double::ToString(double value, int precision)
{
-//Dummy implementation to resolve build break
- return String(L"");
+ return _LocalizedNumParser::ToString(value, "", precision);
}
String
Float::ToString(int precision) const
{
-//Dummy implementation to resolve build break
- return String(L"");
+ return Float::ToString(value, precision);
}
String
String
Float::ToString(float value, int precision)
{
-//Dummy implementation to resolve build break
- return String(L"");
+ return _LocalizedNumParser::ToString(value, "", precision);
}
#include <FBaseSysLog.h>
#include "FBase_LocalizedNumParser.h"
+#define CHECK_NAN_OR_INF_AND_RETURN(value) \
+ if (std::isnan(value)) \
+ { \
+ return String(L"NaN"); \
+ } \
+ if (std::isinf(value)) \
+ { \
+ return String(L"Infinity"); \
+ }
+
namespace Tizen { namespace Base
{
_LocalizedNumParser::ToString(double value, const char* pLocale)
{
ClearLastResult();
-
- if (std::isnan(value))
- {
- return String(L"NaN");
- }
-
- if (std::isinf(value))
- {
- return String(L"Infinity");
- }
+ CHECK_NAN_OR_INF_AND_RETURN(value);
_CLocaleWrapper clocale;
result r = clocale.Construct(pLocale);
- SysTryReturn(NID_BASE, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
+ SysTryReturn(NID_BASE, r == E_SUCCESS, String(L""), r, "[%s] Propagating.", GetErrorMessage(r));
wchar_t sValue[DBL_MAX_LENGTH + 1] = {0, };
swprintf(sValue, sizeof(sValue) / sizeof(sValue[0]), L"%#lg", value);
}
String
-_LocalizedNumParser::ToString(float value, const char* pLocale)
+_LocalizedNumParser::ToString(double value, const char* pLocale, int precision)
{
ClearLastResult();
+ CHECK_NAN_OR_INF_AND_RETURN(value);
- if (std::isnan(value))
- {
- return String(L"NaN");
- }
+ _CLocaleWrapper clocale;
+ result r = clocale.Construct(pLocale);
+ SysTryReturn(NID_BASE, r == E_SUCCESS, String(L""), r, "[%s] Propagating.", GetErrorMessage(r));
- if (std::isinf(value))
- {
- return String(L"Infinity");
- }
+ wchar_t sValue[DBL_MAX_LENGTH + 1] = {0, };
+ swprintf(sValue, sizeof(sValue) / sizeof(sValue[0]), L"%.*f", precision, value);
+
+ return String(sValue);
+}
+
+String
+_LocalizedNumParser::ToString(float value, const char* pLocale)
+{
+ ClearLastResult();
+ CHECK_NAN_OR_INF_AND_RETURN(value);
_CLocaleWrapper clocale;
result r = clocale.Construct(pLocale);
- SysTryReturn(NID_BASE, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
+ SysTryReturn(NID_BASE, r == E_SUCCESS, String(L""), r, "[%s] Propagating.", GetErrorMessage(r));
wchar_t sValue[FLOAT_LENGTH_MAX + 1] = {0, };
swprintf(sValue, sizeof(sValue) / sizeof(sValue[0]), L"%g", value);
return String(sValue);
}
+String
+_LocalizedNumParser::ToString(float value, const char* pLocale, int precision)
+{
+ ClearLastResult();
+ CHECK_NAN_OR_INF_AND_RETURN(value);
+
+ _CLocaleWrapper clocale;
+ result r = clocale.Construct(pLocale);
+ SysTryReturn(NID_BASE, r == E_SUCCESS, String(L""), r, "[%s] Propagating.", GetErrorMessage(r));
+
+ wchar_t sValue[DBL_MAX_LENGTH + 1] = {0, };
+ swprintf(sValue, sizeof(sValue) / sizeof(sValue[0]), L"%.*f", precision, value);
+
+ return String(sValue);
+}
}} // Tizen::Base
* @remarks
* - If the input value is Not-a-Number(NaN), the result is the string "NaN".
* Furthermore, infinity produces the result "Infinity". @n
- * 6 digits are given for the precision of this method. Use String::Format() to set the specific precision.
+ * 6 digits are given for the precision of this method. Use Double::ToString(int precision) to set the specific precision.
* - The behavior of this method is dependent on the specified locale setting.
* - The specific error code can be accessed using the GetLastResult() method.
*/
static String ToString(double value, const char* pLocale);
/**
+ * Locale specifiable version of Double::ToString(int precision). @n
+ * This method is affected by the specified @c pLocale.
+ *
+ * @since 3.0
+ *
+ * @return A string containing a Unicode representation of the specified @c double value
+ * @param[in] value A @c double value to convert
+ * @param[in] pLocale A specific locale identifier. @n
+ * The @c pLocale can have below values.
+ * - "" : the system default locale
+ * - "C" or "POSIX" : the POSIX locale
+ * - "language[_territory][.codeset]" : an implementation-provided locale, e.g. "en_US.utf8", "fr_FR.utf8", etc.
+ * @param[in] precision Number of digits after a decimal separator
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_INVALID_ARG The specified locale identifier is invalid.
+ * @remarks
+ * - If the input value is Not-a-Number(NaN), the result is the string "NaN".
+ * Furthermore, infinity produces the result "Infinity". @n
+ * - The behavior of this method is dependent on the specified locale setting.
+ * - The specific error code can be accessed using the GetLastResult() method.
+ */
+ static String ToString(double value, const char* pLocale, int precision);
+
+ /**
* Locale specifiable version of Float::ToString(). @n
* This method is affected by the specified @c pLocale.
*
* @remarks
* - If the input value is Not-a-Number(NaN), the result is the string "NaN".
* Furthermore, infinity produces the result "Infinity". @n
- * 6 digits are given for the precision of this method. Use String::Format() to set the specific precision.
+ * 6 digits are given for the precision of this method. Use Float::ToString(int precision) to set the specific precision.
* - The behavior of this method is dependent on the specified locale setting.
* - The specific error code can be accessed using the GetLastResult() method.
*/
static String ToString(float value, const char* pLocale);
+ /**
+ * Locale specifiable version of Float::ToString(int precision). @n
+ * This method is affected by the specified @c pLocale.
+ *
+ * @since 3.0
+ *
+ * @return A string containing a Unicode representation of the specified @c float value
+ * @param[in] value A @c float value to convert
+ * @param[in] pLocale A specific locale identifier. @n
+ * The @c pLocale can have below values.
+ * - "" : the system default locale
+ * - "C" or "POSIX" : the POSIX locale
+ * - "language[_territory][.codeset]" : an implementation-provided locale, e.g. "en_US.utf8", "fr_FR.utf8", etc.
+ * @param[in] precision Number of digits after a decimal separator
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_INVALID_ARG The specified locale identifier is invalid.
+ * @remarks
+ * - If the input value is Not-a-Number(NaN), the result is the string "NaN".
+ * Furthermore, infinity produces the result "Infinity". @n
+ * - The behavior of this method is dependent on the specified locale setting.
+ * - The specific error code can be accessed using the GetLastResult() method.
+ */
+ static String ToString(float value, const char* pLocale, int precision);
+
private:
//
// This default constructor is intentionally declared as private because this class is not constructible.
static const int DBL_MAX_LENGTH = 17 + 308 + 3; // significant decimal digits + exponent + extra characters
};
}} // Tizen::Base
-#endif // _FBASE_INTERNAL_LOCALIZED_NUM_PARSER_H_
\ No newline at end of file
+#endif // _FBASE_INTERNAL_LOCALIZED_NUM_PARSER_H_