How to display floating-point numbers with a mantissa set to zero in C++? -
The following code shows floating-point numbers in scientific notation:
float foo = 1.0 ; :: Court :: setf (:: std :: ios :: scientist); :: std :: cout & lt; & Lt; Foo;
This produces this output:
1.000000e-000
What I would like to do is display floating Point numbers in a specific notation that are similar to scientific notation but set to zero with one Manthissa. With the same floating-point number above, it will be produced:
0.100000e + 001
In C, I believe it will be written like this :
printf ("% .6E", FU);
Update: OK, I do not really know how to do it in C. Update 2: An example using iostream formatting was incorrect. I modified it according to Michael Bore's comment.
If you want to do this with ostreams, then I think using 'aspects' It will be required that this small part of C ++ lets you control too much formatting, but you like it.
Here is a description of num_put
, which formats the numbers you did not like, such as:
You can get your Ostream (literally Ostr.imbue ()
) which will include a locale in which you will create numbers as a way of formatting. Want to
I suggest that to convert a number into a string, one should start by typing the function that you want. Once you have that, if you want to completely hog and place & amp; Aspect accessories, you can (or maybe you will decide that it is very complex, which is the end of most people).
Comments
Post a Comment