LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 06-06-2004, 11:42 AM   #1
keefaz
Senior Member
 
Registered: Mar 2004
Distribution: Slackware
Posts: 4,605

Rep: Reputation: 134Reputation: 134
C++ format float number output


Hi,

I don't succeed with formating output for float number, all I want is a list like :
0.00
15.00
12.25
13.56
12.50

from float like :
0.0
15.0
12.25
13.56
12.5

nothing hard but I can not figure out how cout work, I tried :
Code:
cout.precision(3);
cout << showpoint;
cout << 0.0 << "\n" << 15.0 << "\n" << 12.25 << "\n" << 13.56 << "\n" << 12.5 << "\n";
but output is :
0.00
15.0
12.2
13.6
12.5

Any suggestion or where to find man for that will be much apprechated
 
Old 06-06-2004, 11:48 AM   #2
jedi_il
LQ Newbie
 
Registered: Jun 2004
Distribution: gentoo & debian
Posts: 2

Rep: Reputation: 0
try
cout.setf(ios::fixed, ios::floatfield);
cout.precision(2);
 
Old 06-06-2004, 11:51 AM   #3
keefaz
Senior Member
 
Registered: Mar 2004
Distribution: Slackware
Posts: 4,605

Original Poster
Rep: Reputation: 134Reputation: 134
Maaaannny thanks
 
Old 06-06-2004, 02:16 PM   #4
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Rep: Reputation: 32
or just:

printf("%.2f", myfloat);
 
  


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
count digits of a float || convert float to string nadroj Programming 6 07-11-2005 04:52 PM
output number of blank lines tjgadu Linux - Newbie 7 06-09-2005 04:01 PM
assigning a large float number in E notation edM Programming 3 05-09-2005 12:51 PM
How to format a number as 1,234,567 using C? neo_in_matrix Programming 7 01-22-2005 12:42 PM
Could I directly output a binary number? Xiangbuilder Programming 2 10-03-2003 08:27 AM


All times are GMT -5. The time now is 02:07 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration