0

I'm using the following code to print float number (value is of type float):

std::ostringstream ss;
ss << std::fixed << std::setprecision(9) << value;

which works fine most the cases. However, when value is very small I'm getting things like:

2.98e-07

while I'd would expect the following (fixed notation with 9 decimal numbers):

0.0000000289

Thus, what is the way of using std::ostringstream to achive this, please?

fgalan
  • 11,732
  • 9
  • 46
  • 89
  • I have seen several similar questions at StackOverflow, but after browsing some time, I haven't found any one addressing this specific case. However, if I'm wrong I will be more than happy to know and mark this question as duplicated:) – fgalan Nov 25 '15 at 16:20
  • 2
    Can you post the code that reproduces the problem? I [cannot reproduce it](http://coliru.stacked-crooked.com/a/8e357439dbb71c2e). – vsoftco Nov 25 '15 at 16:26
  • Works for me. See [this](http://ideone.com/3OJc5U). Maybe a compiler/platform issue? – crayzeewulf Nov 25 '15 at 16:32
  • Question post include a code snippet, but it lack of context... I have tried to reproduce using a small program (just main() and cout as stream) and the problems is not reproducible, as some reader has suggested. I'm reseraching on it and hope to update my original post (or answering myself :) when found what could be going on... – fgalan Nov 25 '15 at 16:49

1 Answers1

0

At the end, the problem was not in the C++ program that generates the float number (that as some users have report, it is ok) but in the program that I use to beautify the output of the C++ program. Thus this question is solved (although a new one about the beautifier opens).

Community
  • 1
  • 1
fgalan
  • 11,732
  • 9
  • 46
  • 89