| | |
Drop 0 in floating point variable 0.233
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
My first question is: why bother? Unless there's a trick that's slipped my mind, you need to copy the value into a string and then remove the first character:
That's hardly worth the effort for something so small as removing a 0 for no apparent benefit.
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <sstream> using namespace std; int main() { double f = 0.123; ostringstream sout; sout<< f; string s = sout.str(); cout<< s.substr(1, s.length()) <<endl; }
New members chased away this month: 4
For the benifits of others:
You must include <iomanip> to use this manipulator.
You must include <iomanip> to use this manipulator.
C++ Syntax (Toggle Plain Text)
// setprecision example #include <iostream> #include <iomanip> using namespace std; int main () { double f =3.14159; cout << setprecision (5) << f << endl; cout << setprecision (9) << f << endl; return 0; }
A Hacker's Mind:
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes..." - J.D.Salinger
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes..." - J.D.Salinger
![]() |
Similar Threads
- a simple way to print a binary representation of a floating point number? (C++)
- Floating Decimal Variable? (Python)
- floating point/character (C)
- More precise floating point arithmetic (C++)
- Matlab - Is this a floating point arithmetic problem? (Computer Science)
- floating point (C++)
Other Threads in the C++ Forum
- Previous Thread: Programming Class Help!
- Next Thread: I need a solution for a opengl thing
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream image input int java lazy lib loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






