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

java - BeanIO write annotated class to fixedlength -

Using Java 8 lambdas/transformations to combine and flatten two Maps -

How to connect android app to App engine -