C++ significant figures

2020-06-16 02:11发布

How can I do math involving significant figures in C++? I want this to work correct with measured data from chemistry and physics experiments. An example: 65 / 5 = 10. I would need to get rid of unneeded decimal places and replace some digits with 0s.

Thanks!

7条回答
\"骚年 ilove
2楼-- · 2020-06-16 02:48

This should get you what you need:

std::cout.precision(x); // x would be the number of significant figures to output
查看更多
登录 后发表回答