Adding overload for string conversion to float directly
This commit is contained in:
parent
bea962b6fe
commit
f025c9cd6f
2 changed files with 14 additions and 3 deletions
|
@ -51,16 +51,26 @@ bool is_decimal_separator_point()
|
|||
return str[1] == '.';
|
||||
}
|
||||
|
||||
|
||||
double string_to_double_decimal_point(const std::string_view str, size_t* pos /* = nullptr*/)
|
||||
template<class T>
|
||||
static T string_to_floating_decimal_point(const std::string_view str, size_t* pos /* = nullptr*/)
|
||||
{
|
||||
double out;
|
||||
T out;
|
||||
size_t p = fast_float::from_chars(str.data(), str.data() + str.size(), out).ptr - str.data();
|
||||
if (pos)
|
||||
*pos = p;
|
||||
return out;
|
||||
}
|
||||
|
||||
double string_to_double_decimal_point(const std::string_view str, size_t* pos /* = nullptr*/)
|
||||
{
|
||||
return string_to_floating_decimal_point<double>(str, pos);
|
||||
}
|
||||
|
||||
float string_to_float_decimal_point(const std::string_view str, size_t* pos /* = nullptr*/)
|
||||
{
|
||||
return string_to_floating_decimal_point<float>(str, pos);
|
||||
}
|
||||
|
||||
std::string float_to_string_decimal_point(double value, int precision/* = -1*/)
|
||||
{
|
||||
// Our Windows build server fully supports C++17 std::to_chars. Let's use it.
|
||||
|
|
|
@ -42,6 +42,7 @@ bool is_decimal_separator_point();
|
|||
std::string float_to_string_decimal_point(double value, int precision = -1);
|
||||
//std::string float_to_string_decimal_point(float value, int precision = -1);
|
||||
double string_to_double_decimal_point(const std::string_view str, size_t* pos = nullptr);
|
||||
float string_to_float_decimal_point (const std::string_view str, size_t* pos = nullptr);
|
||||
|
||||
// Set locales to "C".
|
||||
inline void set_c_locales()
|
||||
|
|
Loading…
Reference in a new issue