0

Assuming I have this :

double a = 51234;
printf("%8.3e",a);

The output that I get is

5.123e+004

How do I delete the zeros and get an output like this : 5.123e+4 ?

  • 1
    strange, I get 5.123e+04, I see @Upgrade are you using windows for this? – Har Nov 01 '20 at 21:18
  • Yes but still the output that you get is not what I want . Is there a possibility to delete the zeros in C ? –  Nov 01 '20 at 21:24
  • 3
    You could use `snprintf` then change the string buffer. See [this C reference](https://en.cppreference.com/w/c) and read [*Modern C*](https://modernc.gforge.inria.fr/) – Basile Starynkevitch Nov 01 '20 at 21:25
  • 1
    I agree with @BasileStarynkevitch there is no way to change the leading zeroes according to the C standard. You would have to do that yourself using snprintf. Read the following stackoverflow question it is similar to what you have asked: https://stackoverflow.com/questions/64637040/e-format-with-printf-not-printing-the-desired-output#64637040 – Har Nov 01 '20 at 21:27
  • 1
    @Har you sent the link of my question –  Nov 01 '20 at 21:29
  • Sorry here is the updated link: https://stackoverflow.com/questions/31331723/how-to-control-the-number-of-exponent-digits-after-e-in-c-printf-e – Har Nov 01 '20 at 21:32

0 Answers0