VTK
9.2.20230603
|
Convert floating and fixed point numbers to strings. More...
#include <vtkNumberToString.h>
Classes | |
struct | TagDouble |
struct | TagFloat |
Public Member Functions | |
template<typename T > | |
const T & | operator() (const T &val) const |
TagDouble | operator() (const double &val) const |
TagFloat | operator() (const float &val) const |
void | SetLowExponent (int lowExponent) |
Set/Get the LowExponent for string conversion. More... | |
int | GetLowExponent () |
Set/Get the LowExponent for string conversion. More... | |
void | SetHighExponent (int highExponent) |
Set/Get the HighExponent for string conversion. More... | |
int | GetHighExponent () |
Set/Get the HighExponent for string conversion. More... | |
std::string | Convert (double val) |
Convert a number to an accurate string representation of that number. More... | |
std::string | Convert (float val) |
Set/Get the HighExponent for string conversion. More... | |
template<typename T > | |
std::string | Convert (const T &val) |
Set/Get the HighExponent for string conversion. More... | |
Convert floating and fixed point numbers to strings.
This class uses the double-conversion library to convert float and double numbers to std::string without numerical precision errors. It is possible to specify the low and high exponent where the string representation will switch to scientific notation instead of fixed point notation.
For other types, this class rely on std::to_string.
Typical use:
Definition at line 59 of file vtkNumberToString.h.
void vtkNumberToString::SetLowExponent | ( | int | lowExponent | ) |
Set/Get the LowExponent for string conversion.
It correspond to the closest to zero exponent value that will use fixed point notation in the returned string instead of a scientific notation. eg: LowExponent = 6, 1e-6 -> "0.000001" LowExponent = 5, 1e-6 -> "1e-6"
int vtkNumberToString::GetLowExponent | ( | ) |
Set/Get the LowExponent for string conversion.
It correspond to the closest to zero exponent value that will use fixed point notation in the returned string instead of a scientific notation. eg: LowExponent = 6, 1e-6 -> "0.000001" LowExponent = 5, 1e-6 -> "1e-6"
void vtkNumberToString::SetHighExponent | ( | int | highExponent | ) |
Set/Get the HighExponent for string conversion.
HighExponent correspond to the highest exponent value that will use fixed point notation in the returned string instead of a scientific notation. HighExponent = 6, 1e6 -> "1000000" HighExponent = 5, 1e6 -> "1e6"
int vtkNumberToString::GetHighExponent | ( | ) |
Set/Get the HighExponent for string conversion.
HighExponent correspond to the highest exponent value that will use fixed point notation in the returned string instead of a scientific notation. HighExponent = 6, 1e6 -> "1000000" HighExponent = 5, 1e6 -> "1e6"
std::string vtkNumberToString::Convert | ( | double | val | ) |
Convert a number to an accurate string representation of that number.
A templated generic implementation is provided, which rely on std::to_string for types other than double or float.
std::string vtkNumberToString::Convert | ( | float | val | ) |
Set/Get the HighExponent for string conversion.
HighExponent correspond to the highest exponent value that will use fixed point notation in the returned string instead of a scientific notation. HighExponent = 6, 1e6 -> "1000000" HighExponent = 5, 1e6 -> "1e6"
|
inline |
Set/Get the HighExponent for string conversion.
HighExponent correspond to the highest exponent value that will use fixed point notation in the returned string instead of a scientific notation. HighExponent = 6, 1e6 -> "1000000" HighExponent = 5, 1e6 -> "1e6"
Definition at line 95 of file vtkNumberToString.h.
|
inline |
Definition at line 120 of file vtkNumberToString.h.
|
inline |
Definition at line 125 of file vtkNumberToString.h.
|
inline |
Definition at line 127 of file vtkNumberToString.h.