I want a particular number of digits in double/float primitive type. Is there any way to do this?
For example: (fixed to 6 digits)
- If we have 12.666666667 gives output as 12.6667
- If we have 5.6666666667 gives output as 5.66667
- However, if we have 9.00000000 gives output as only 9.*
For, more clear understanding, I have attached an image.enter image description here
How to replicate the same output that I got from below mentioned code in java:
#include<iostream>
using namespace std;
int main()
{
float num = 9.34333666666663;
float num2 = 12.0000000
cout << num;
cout << num2;
return 0;
}
Output:-
9.34334
12