Lost Password?


Go Back   CodeCall Programming Forum > Software Development > C and C++

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-23-2007, 08:29 AM
Nille's Avatar   
Nille Nille is offline
Learning Programmer
 
Join Date: Apr 2007
Location: Sweden
Age: 19
Posts: 37
Rep Power: 6
Nille is on a distinguished road
Default A problem with setprecision

Ok ive got a bit of a problem with setprecision.

I have made a program that outputs a bunch of numbers all ending with 2 decimals (using setprecision(2)) and then it saves it in a .txt file but instead of saving 2 decimals it writes stuff like 8e+004.

can i not use setprecision when im writing to a file or am i just doing it the wrong way?

plz help //Nille.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 08-04-2007, 06:58 AM
v0id's Avatar   
v0id v0id is offline
Retired
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,654
Last Blog:
CherryPy(thon)
Rep Power: 29
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

I think you've maybe misunderstood what std::setprecision is doing. You aren't setting the precision for the decimals, but for the whole... "number."

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

int main()
{
	double fNumber = 12.34;
	
	std::cout << std::setprecision(1) << fNumber << std::endl; // 1e+001
	std::cout << std::setprecision(2) << fNumber << std::endl; // 12
	std::cout << std::setprecision(3) << fNumber << std::endl; // 12.3
	std::cout << std::setprecision(4) << fNumber << std::endl; // 12.34
	
	return 0;
}
__________________
05-03-2007 - 11-13-2008
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Peculiar UI Problem Needs Tackling adriyel C# Programming 2 04-06-2008 08:46 AM
i have a problem please help me!!!???? stack Java Help 8 09-22-2007 04:17 PM
[C] Comparison problem Alhazred C and C++ 1 08-29-2007 05:58 AM
problem with boot gwo Computer Hardware 6 07-18-2007 04:15 AM
A small problem in the output The_Master C and C++ 3 12-13-2006 01:04 PM


All times are GMT -5. The time now is 03:19 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 100%


Complete - Celebrate!

Ads