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

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -