-3

I have a problem. The task is to calculate x = pow (a, 5) - 2*sqrt (abs (b)) + a * b * c and print out the result with to number behind the decimal point. I googled and found out the use of iomanip library and setprecision() function, and it worked. But I don't know why when the input is -10, -20, -30, it printed out -106008.95 while it should be -106008.94

Please help me to fix this, thank you so much

1 Answers1

-1

The actual output with 9 decimal point precission is -106008.945 so, when you are setting precission to 8 it just omit the 9th decimal point and as this value '5' (9th decimal point) is in the range of [ 5 to 9 ] they are just adding '1' to 8th decimal point value.

so, -106008.945 becomes -106008.95 when it comes to 8 decimal point precission. If you want -106008.945 to become -106008.94 when you set the decimal point to 8, you can checkout this stackoverflow link where exactly this case was discussed

Nafiul Alam Fuji
  • 407
  • 7
  • 17
  • this is funny that, trying to help out newbies results in negative behaviour in stackoverflow now a days. The guy is super newbie to ask that ques and it also took me some time to get what he even asking. I tried my best to satisfy his ans but here it goes..! – Nafiul Alam Fuji Oct 26 '22 at 07:15