Multiple precision settings?

Multiple precisions in one line of code?

Page 1 of 1

1 Replies - 862 Views - Last Post: 21 February 2007 - 10:50 AM Rate Topic: -----

#1 agentjk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 11-February 07

Multiple precision settings?

Post icon  Posted 21 February 2007 - 10:40 AM

I need to print 333.546372 in a field width of 15, left justified, with precisions of 1,2,3,4,5.
Heres what I have so far.
#include <stdio.h>

int main()

{
	printf("|%-15.1|","333.546372\n");
	

	return 0;
}



Is there a way to accomplish this with one line of code?
Thanks
Is This A Good Question/Topic? 0
  • +

Replies To: Multiple precision settings?

#2 ajwsurfer  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 21
  • View blog
  • Posts: 373
  • Joined: 24-October 06

Re: Multiple precision settings?

Posted 21 February 2007 - 10:50 AM

You can do it with one line of code.

printf( "%#.#f %#.#f %#.#f %#.#f \n", 333.546372, 333.546372, ... );

take a look at the examples at the bottom of this page
http://www.cplusplus...dio/printf.html
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1