Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/150.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 指数型大数的双到字符串转换_C++_C++11 - Fatal编程技术网

C++ 指数型大数的双到字符串转换

C++ 指数型大数的双到字符串转换,c++,c++11,C++,C++11,我有一个应用程序,我必须处理非常大的数字。应用程序API给了我一个数字,然后我必须将它转换成字符串并发送给进一步的处理。 代码接收号码为-1535625179.1619387 那么对于转换,我使用了- char buffer[255]; sprintf(buffer, "%e", OverallVolume); //OverallVolume has the above value. 现在这里是缓冲区变量返回1.535625e+009,标准化为1535625000.00 但我的应用程序显示的值

我有一个应用程序,我必须处理非常大的数字。应用程序API给了我一个数字,然后我必须将它转换成字符串并发送给进一步的处理。 代码接收号码为-1535625179.1619387

那么对于转换,我使用了-

char buffer[255];
sprintf(buffer, "%e", OverallVolume); //OverallVolume has the above value.
现在这里是缓冲区变量返回1.535625e+009,标准化为1535625000.00 但我的应用程序显示的值为1.5356252e+09,标准化为1535625200.00


所以我想问一下,我应该使用什么方法将Double转换为String,以便我的结果值与应用程序显示的值相匹配。

如果我正确理解您的问题,您希望小数点后出现7位数字。为此,请按如下方式指定精度:

sprintf(buffer, "%.7e", OverallVolume); // buffer contains 1.5356252e+09


此外,由于这是标记C++,这里是使用IO流打印相同结果的版本。

#include <ios>
#include <iomanip>
#include <iostream>
#include <sstream>

int main() 
{
    double OverallVolume = 1535625179.1619387;
    std::ostringstream ss;

    ss << std::scientific << std::setprecision(7) << OverallVolume;
    std::cout << ss.str() << '\n'; // prints 1.5356252e+09
}
#包括
#包括
#包括
#包括
int main()
{
双倍总容积=1535625179.1619387;
std::ostringstream ss;
党卫军