PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, August 11, 2022

[FIXED] How to use printf so that zeros are printed with decimals

 August 11, 2022     c, decimal, double, printf, stdio     No comments   

Issue

I'm running a simple calculation in C, for which, sometimes, the result is exactly 0. I then print these results using something like printf("%0.4g", result). If the result is not 0, it does what I want it do, e.g., the output may be 1.796e+04. However, if the result is exactly 0, which it often is, the output will be 0.

My question is, what can I do to print 0.0000, with 4 decimals, even though the number there might be exactly 0?


Solution

the statement

printf("%0.4e\n", res);

might solve your problem!



Answered By - Patrick Bauers
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing