mirror of https://github.com/Icinga/icinga2.git
parent
bc6f7d7a21
commit
039461e218
|
@ -35,6 +35,12 @@ String Convert::ToString(const Value& val)
|
|||
|
||||
String Convert::ToString(double val)
|
||||
{
|
||||
double integral;
|
||||
double fractional = std::modf(val, &integral);
|
||||
|
||||
if (fractional == 0)
|
||||
return Convert::ToString(static_cast<long>(val));
|
||||
|
||||
std::ostringstream msgbuf;
|
||||
msgbuf << std::fixed << val;
|
||||
return msgbuf.str();
|
||||
|
|
|
@ -56,19 +56,12 @@ Value::operator double(void) const
|
|||
Value::operator String(void) const
|
||||
{
|
||||
Object *object;
|
||||
double dvalue, integral, fractional;
|
||||
|
||||
switch (GetType()) {
|
||||
case ValueEmpty:
|
||||
return String();
|
||||
case ValueNumber:
|
||||
dvalue = boost::get<double>(m_Value);
|
||||
fractional = std::modf(dvalue, &integral);
|
||||
|
||||
if (fractional != 0)
|
||||
return Convert::ToString(dvalue);
|
||||
else
|
||||
return Convert::ToString(static_cast<long>(dvalue));
|
||||
return Convert::ToString(boost::get<double>(m_Value));
|
||||
case ValueBoolean:
|
||||
if (boost::get<bool>(m_Value))
|
||||
return "true";
|
||||
|
|
|
@ -46,14 +46,14 @@ BOOST_AUTO_TEST_CASE(todouble)
|
|||
BOOST_AUTO_TEST_CASE(tostring)
|
||||
{
|
||||
BOOST_CHECK(Convert::ToString(7) == "7");
|
||||
BOOST_CHECK(Convert::ToString(7.5) == "7.5");
|
||||
BOOST_CHECK(Convert::ToString(7.5) == "7.500000");
|
||||
BOOST_CHECK(Convert::ToString("hello") == "hello");
|
||||
|
||||
String str = "hello";
|
||||
BOOST_CHECK(Convert::ToString(str) == "hello");
|
||||
|
||||
BOOST_CHECK(Convert::ToString(Value(7)) == "7");
|
||||
BOOST_CHECK(Convert::ToString(Value(7.5)) == "7.5");
|
||||
BOOST_CHECK(Convert::ToString(Value(7.5)) == "7.500000");
|
||||
BOOST_CHECK(Convert::ToString(Value("hello")) == "hello");
|
||||
BOOST_CHECK(Convert::ToString(Value("hello hello")) == "hello hello");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue