![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
|
Hello all,
Because now I'm converting my friends pascal programs to C++ to show him how much c++ is more powerful compared to pascal I found some difficulties. In pascal, if we have the number pi = 3.141592654 and he issues these statements: writeln(pi:1:4); In C++ I can use this:cout.precision(4); So I can only contol the length of the whole number, but I cannot define before the dot and after it. I'm sure that there's some way of doing it, but I cannot find it anywhere... Thanks in advanceCheers, gamehack |
|
|
|
|
|
#2 |
|
Expert Programmer
|
lookup cout.setf( ). There is a flag in there I believe you set which will cause cout.precision to count using decimal precision only.
__________________
Clifford Matthew Roche <geek@cliffordroche.com> Web Hosting: http://www.crd-hosting.com Consulting: http://www.crdev-consulting.com |
|
|
|
|
|
#3 |
|
Newbie
|
So I looked in a book and found the answer. To define the precision right from the decimal you have to set
cout.setf(ios_base::fixed); cout.precision(n); Cheers, gamehack |
|
|
|
|
|
#4 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
printf(%1.4f", pi); Don't know if that's what you want.
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|