aboutsummaryrefslogtreecommitdiffstats
path: root/include/vector2.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/vector2.hpp')
-rw-r--r--include/vector2.hpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/include/vector2.hpp b/include/vector2.hpp
index 5c9f9e1..54b0809 100644
--- a/include/vector2.hpp
+++ b/include/vector2.hpp
@@ -4,6 +4,9 @@
#include <string>
#include <type_traits>
+#include <sstream>
+#include <iomanip>
+
template<typename T>
struct vector2 {
static_assert(std::is_arithmetic<T>::value, "vector2 members must be an arithmetic type (i.e. numbers)");
@@ -123,8 +126,18 @@ struct vector2 {
}
// other functions
- std::string toString(void) const {
- return "(" + std::to_string(x) + ", " + std::to_string(y) + ")";
+ std::string toString(int precision = -1) const {
+ std::stringstream ss;
+ std::string sx, sy;
+ ss << std::fixed;
+ if (precision > -1)
+ ss << std::setprecision(precision);
+ ss << x;
+ sx = ss.str();
+ ss.str(std::string());
+ ss << y;
+ sy = ss.str();
+ return "(" + sx + ", " + sy + ")";
}
};