summaryrefslogtreecommitdiff
path: root/src/common/conversion.cpp
blob: 0bdc81ab757387878d001caef7901a95fcde469b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "conversion.hpp"

namespace common
{

common::UniquePtr<common::String> doubleToStr(double num, unsigned int width,
											  unsigned int precision)
{
	auto str = common::make_unique<common::String>(width + precision);

	dtostrf(num, static_cast<signed char>(width), static_cast<unsigned char>(precision),
			str->c_str);

	return str;
}

common::UniquePtr<common::String> intToStr(int num)
{
	auto width = static_cast<unsigned int>(log10(num));

	auto str = common::make_unique<common::String>(width + 1U);

	dtostrf(num, static_cast<signed char>(width + 1U), 0U, str->c_str);

	return str;
}

common::UniquePtr<common::String> uintToStr(unsigned int num)
{
	auto width = static_cast<unsigned int>(log10(num));

	auto str = common::make_unique<common::String>(width + 1U);

	dtostrf(num, static_cast<signed char>(width + 1U), 0U, str->c_str);

	return str;
}

} // namespace common