且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C ++ 11 std :: to_string(double) - 没有尾零

更新时间:2023-11-14 15:49:46

C ++ 11标准明确地说( 21.5 / 7 ):

The C++11 Standard explicitely says (21.5/7):


返回:每个函数返回一个字符串对象,该对象包含其参数值的字符表示,该参数将通过调用具有格式说明符%d,%u的sprintf(buf,fmt, %ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld / p>

Returns: Each function returns a string object holding the character representation of the value of its argument that would be generated by calling sprintf(buf, fmt, val) with a format specifier of "%d", "%u", "%ld", "%lu", "%lld", "%llu", "%f", "%f", or "%Lf", respectively, where buf designates an internal character buffer of sufficient size

以此顺序声明的函数:

string to_string(int val);
string to_string(unsigned val);
string to_string(long val);
string to_string(unsigned long val);
string to_string(long long val);
string to_string(unsigned long long val);
string to_string(float val);
string to_string(double val);
string to_string(long double val);

因此,您无法控制结果字符串的格式。

Thus, you cannot control the formatting of the resulting string.