utils.h 607 Bytes
Newer Older
gabime's avatar
gabime committed
1 2 3 4
//
// Copyright(c) 2015 Gabi Melman.
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
//
gabime's avatar
gabime committed
5

gabi's avatar
gabi committed
6 7 8 9 10 11
#pragma once

#include <sstream>
#include <iomanip>
#include <locale>

12 13
namespace utils
{
gabi's avatar
gabi committed
14 15

template<typename T>
16
inline std::string format(const T& value)
gabi's avatar
gabi committed
17
{
gabime's avatar
gabime committed
18 19 20 21 22
    static std::locale loc("");
    std::stringstream ss;
    ss.imbue(loc);
    ss << value;
    return ss.str();
gabi's avatar
gabi committed
23 24
}

gabime's avatar
gabime committed
25
template<>
26
inline std::string format(const double & value)
gabime's avatar
gabime committed
27
{
gabime's avatar
gabime committed
28 29 30 31 32
    static std::locale loc("");
    std::stringstream ss;
    ss.imbue(loc);
    ss << std::fixed << std::setprecision(1) << value;
    return ss.str();
gabime's avatar
gabime committed
33 34
}

gabime's avatar
gabime committed
35
}