I tried following:
std::cout << std::hex << 17.0625;
But it dumped it in decimal. I'd like to see 11.01 (17.0625 in hex). How can I print some floating point value in hex?
Please do not offer solutions like:
void outhexdigits(std::ostream& out, fp_t d, int max_chars=160)
{
while(d > 0. && max_chars)
{
while(d < 1. && max_chars){
out << '0';
--max_chars;
d*=16;
}
if (d>=1. && max_chars) {
int i = 0;
while (d>=1.)
++i, --d;
out << std::hex << i;
--max_chars;
}
}
}
Is there any way to dump float numbers in hex in STL/boost?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…