#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int T; cin >> T;
cout << setiosflags(ios::uppercase);
cout << setw(0xf) << internal;
while (T--) {
double A; cin >> A;
double B; cin >> B;
double C; cin >> C;
cout << fixed << setprecision(0) << hex << showbase << A << '\n';
cout << fixed << setprecision(2) << showpos << right << setfill('_') << setw(15) << B << '\n';
cout << fixed << setprecision(9) << scientific << C;
}
return 0;
}
This is the problems that I can't solve:
I want to turn number
Ainto a hexadecimal number (including the0xprefix) and remove its decimal.Ex: A = 1345.6454 => I just take 1345 and remove 6454.
In the output of the above code, number
Cdisplays a+sign and I want to remove it.
Does someone know how to solve these problems?
Per https://en.cppreference.com/w/cpp/io/manip/fixed:
To truncate the decimal off of a floating-point number, cast the value to an integer, eg:
Per https://en.cppreference.com/w/cpp/locale/num_put/put:
And per https://en.cppreference.com/w/cpp/io/c/fprintf:
You have enabled
showposwhen printingB, and it is still enabled when printingC.You can use
std::resetiosflags(std::ios::showpos)orstd::noshowposto disableshowpos: