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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -