2

From C Primer Plus, the 6th edition Chapter 4, Review Questions enter image description here

I'm working on the last question, I assumed the answer is %12.2e, but it display on the screen like '2.33e+02', one '0' missing.

I wonder if there is a way to change the display mode of exponent form floating-point number.

I'm using VS2015.

Morris Li
  • 93
  • 9
  • 2
    Well, [this page](http://en.cppreference.com/w/cpp/io/c/fprintf) says "The exponent contains at least two digits, more digits are used **only if necessary**" for the `e` notation (emphasis mine). Not sure what more to say. – Mr Lister Nov 18 '16 at 14:43
  • AFAICT, 2 digits of exponent are guaranteed; 3 digits are only used when necessary. IOW, you'd have to post-process what the system provides (using `snprintf()` or similar to format to a string and then editing the string). – Jonathan Leffler Nov 18 '16 at 14:45
  • if you're on MSVC then it can be set by `_set_output_format` – phuclv Nov 18 '16 at 14:49
  • 1
    OOPs since VS2015 it was removed and it can only set to 2 digits https://msdn.microsoft.com/en-us/library/0fatw238(v=vs.140).aspx – phuclv Nov 18 '16 at 14:51
  • @JoeDF unfortunately, the answer in appendix is exactly what I assumed, so I have to find it out here. Thank you all the same :) – Morris Li Nov 18 '16 at 14:57
  • [How to control the number of exponent digits after 'e' in C printf %e?](http://stackoverflow.com/q/31331723/995714) – phuclv Nov 18 '16 at 15:02

0 Answers0