Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

uncertain results from "printf" with "%g"

Status
Not open for further replies.

lehe

Programmer
Jul 18, 2008
5
US
Hi,
When using "..printf Functions" with Conversion specifier type "%g", it gives different results under different environment. For example, "sprintf(string,"%g",1e-6);" gives "1e-006" in Windows (Visual C++) and "1e-06" in Linux (gcc). Maybe I am wrong about it. Is it possible to get the same format under whatever operating system or compiler?
Thanks in advance!
 
None the less you can't control number of digits or + sign occurence after E (or e) in such manner (when %g treated as %e). So it's and will be implementation-defined issue.

Apropos, is it a good style - to post the answer to several forums at the same time?
 
Also, if you decide to change to f format, remember that the n.m in a %g and the n.m in a %f are interpreted differently.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top