In my book it said that i can use this
cout.setf(ios::fixed, ios::floatfield);
cout.precision(2);
But what if i want to round it off to the nearest 0.50?
like double Cash = 10.34 will be 10.50
Thanks.
This is a discussion on Round off to nearest .50 within the C++ Programming forums, part of the General Programming Boards category; In my book it said that i can use this cout.setf(ios::fixed, ios::floatfield); cout.precision(2); But what if i want to round ...
In my book it said that i can use this
cout.setf(ios::fixed, ios::floatfield);
cout.precision(2);
But what if i want to round it off to the nearest 0.50?
like double Cash = 10.34 will be 10.50
Thanks.
Last edited by major_small; 11-20-2003 at 07:28 AM.
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT
I/O functions don't do math. Just round it manually.
Code:double round(double number) { double change = number - (int)number; number -= change; if(change < 0.25) change = 0; else if(change > 0.75) change = 1; else change = 0.50; return number + change; }
Code:int main(void){srand(time(0));for(double l=rand(),l0=0,l00=0;;l0+=0.1){for(double l000=0;l000 <1;l000+=.001,l+=((double)rand()/RAND_MAX)/0x64,l00+=((sin(l*0x8*atan(l0)*l000-(l0*0x8*atan (l)))*0.5)+0.5)){l00-=floor(l00);for(size_t l0000=0,l00000=(size_t)(0x50*(l00));l0000<l00000;++l0000 )putchar(0x20);putchar(0x61+(int)((double)rand()/RAND_MAX*0x1a));putchar('\n');}}return 0;}