LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-25-2003, 09:40 AM   #1
boa
LQ Newbie
 
Registered: Jun 2003
Posts: 17

Rep: Reputation: 0
Question Formatted output with g++


How do I get doubles to display with the resolution I want?

setprecision does not work. Here is an example program:

Code:
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
   double d=0.;
   for (int i=0; i<10; i++)
   {
      d += 0.5;
      cout << setw(12) << setprecision(6) << d << endl;
   }
}
The output looks like this:
Code:
         0.5
           1
         1.5
           2
         2.5
           3
         3.5
           4
         4.5
           5
I want to display the trailing 000's

Last edited by boa; 11-25-2003 at 09:44 AM.
 
Old 11-25-2003, 10:40 AM   #2
LogicG8
Member
 
Registered: Jun 2003
Location: Long Island, NY
Distribution: Gentoo Unstable (what a misnomer)
Posts: 380

Rep: Reputation: 30
http://216.239.57.104/search?q=cache:uL-9MXQ8mhEJ:http://www.coding-zone.co.uk/cpp/ART...hl=en&ie=UTF-8
 
Old 11-25-2003, 10:44 AM   #3
MartinN
Member
 
Registered: Nov 2003
Location: Ronneby, Sweden
Posts: 555

Rep: Reputation: 30
Keyword showpoint:
Code:
      cout << setw(12) << setprecision(6) << showpoint << d << endl;
Martin
 
Old 11-25-2003, 10:57 AM   #4
boa
LQ Newbie
 
Registered: Jun 2003
Posts: 17

Original Poster
Rep: Reputation: 0
"showpoint" works great. Thanks
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to get a formatted output of the tcpdump abirami Linux - Networking 4 10-18-2004 01:57 AM
Via AC'97 5.1 Optical Output or Audigy 4.1 Output Nza Fedora 3 06-01-2004 08:49 AM
the sound gives output when using mic but no output when run a music file medo Debian 0 04-19-2004 08:17 PM
How to display formatted floats rkrijger Linux - Software 4 10-21-2003 09:52 AM
what if i formatted it vfat ? RHlinux9 Linux - Newbie 4 09-16-2003 12:57 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration