GMP 浮动值 - 以 10 为基数以给定精度打印它们
GMP floating values - print them with given precision in base 10
假设我有一个
mpf_t number;
等于 1.25。我想以给定的精度打印它,例如,即使会有尾随零
1.2500000
当我尝试使用 mpf_get_str 函数打印它时,它会以科学 (e( 格式打印,
mpf_out_str(stdout,10,7,number); //prints 0.125e1
当我使用 c++ 的 cout 时,mpf_t<<过载,
cout << number << endl; //prints 1.25
当我尝试通过在 cout 中调用 setprecision(给定精度(来打印它时,我仍然得到 1.25
cout << setprecision(7) << number << endl; //prints 1.25
那么,我怎样才能按照自己的意愿打印数字呢?
您需要将 std::fixed 发送到 std::cout。
#include <iostream>
#include <gmpxx.h>
int main(int argc,char* argv[])
{
mpf_t mpft;
mpf_init(mpft);
mpf_set_d(mpft,1.25);
std::cout.precision(7);
std::cout << std::fixed;
std::cout << mpft << std::endl;
return 0;
}
相关文章:
- 如何打印boost多精度128位无符号整数
- 为什么 std::cout 打印浮点数、双精度和长双精度到相同的小数精度?
- 打印双精度的整个非小数部分
- C++正确书写和打印复数精度 (cout) 的问题?
- 如何在C++中只打印小数点而不设置限制,但动态设置精度
- 什么样的 GCC 优化可能会根据是否打印来更改双精度?
- 在 c++ 中使用浮点数、双精度打印十进制
- 双精度未打印出来
- 使用 Catch2 以全精度打印浮点值
- 以其精度打印双重
- 如何在不丢失第一位数字的情况下打印出双精度值
- 如何在 for 循环内部或外部打印双精度变量
- 使用 cout 以精度 4 打印双倍
- 长双精度在 MinGW 上打印错误
- 对应该返回的双精度变量进行舍入,而不是打印
- 以 C++ 为单位设置默认浮点打印精度
- GMP 浮动值 - 以 10 为基数以给定精度打印它们
- 我应该使用wsprintf()将双精度打印为宽字符串吗
- 双精度/打印在c++中不能处理14位数字
- c++长双精度打印所有数字