c++ - why does cout remove the trailing zeroes for floating point numbers -


so have code

template <typename t, typename t2> void print (const t& a, const t2& b) { cout << a<<endl<<b<<endl ; }  int main(){ float i=1.002; float j=1.000; print(i,j);  return 0; } 

the output

 1.002  1 

what dont why cout remove zeroes although have specified them during initailisation , know wont make difference m curious why happen.

because of way number stored.

the ieee floating point representation not have notion of significant digits. numbers 1.0 or 1.000 same in binary notation.

you have specify precision when printing.

python instance type decimal behaves want.


Comments

Popular posts from this blog

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

c# - Search and Add Comment with OpenXML for Word -