要用兩次fixed和setprecision:
cout << "|" << fixed << setprecision(4) << n << "|=" << fixed << setprecision(4) << n << endl ;
}
else {
cout << "|" << fixed << setprecision(4) << n << "|=" << fixed << setprecision(4) << -n << endl ;