【发布时间】:2022-01-02 14:27:13
【问题描述】:
我想要 double/float 原始类型的特定位数。有没有办法做到这一点?
例如:(固定为6位)
- 如果我们有 12.666666667,则输出为 12.6667
- 如果我们有 5.6666666667,则输出为 5.66667
- 但是,如果我们有 9.00000000,则输出仅为 9.*
为了,更清楚的理解,我附上一张图片。enter image description here
如何复制我从下面提到的 java 代码中得到的相同输出:
#include<iostream>
using namespace std;
int main()
{
float num = 9.34333666666663;
float num2 = 12.0000000
cout << num;
cout << num2;
return 0;
}
输出:-
9.34334
12
【问题讨论】:
-
那么你尝试了什么?
-
这能回答你的问题吗? How to format Double with dot?
标签: java floating-point decimal precision