Re: Problem with printf formats
- From: "Chuck F. " <cbfalconer@xxxxxxxxx>
- Date: Tue, 20 Dec 2005 07:06:42 -0500
Guenther Sohler wrote: >
I have following code:
int main(void) { printf("%.3lf\n",-2158470*0.001); }
it prints
-2158.470
How can i disable '0' at the end, if they are not needed ?
Is there a possibility just to write %lf and just print as many digits as needed to represent the number ?
You are asking the wrong question. The trailing zero is needed to represent the number. Otherwise how could you distinguish it from:
printf("%.2f\n", -2158471 * 0.001)(always assuming that -2158471 does not create an overflow)
Your question, I believe, is "how to suppress trailing zeroes". A little thought and an intermediary buffer should give you a suitable answer for that.
-- A: Because it fouls the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing on usenet and in e-mail? .
- Follow-Ups:
- Re: Problem with printf formats
- From: Guenther Sohler
- Re: Problem with printf formats
- References:
- Problem with printf formats
- From: Guenther Sohler
- Problem with printf formats
- Prev by Date: Re: too much time for internet and pc and no time for to walk and sport for you
- Next by Date: Re: Problem with printf formats
- Previous by thread: Problem with printf formats
- Next by thread: Re: Problem with printf formats
- Index(es):
Relevant Pages
|