Boost :: format gives different results than round

I would like to understand why

double nbr = 102262.5;

boost::format("%.0f") % nbr;

gives 102262, but round(102262.5)gives102263.0

If we take another approximate value 34087.5

boost::format("%.0f") % nbr

gives 34088and round(34087.5)gives the same34088

Does this mean that round implements a more complex algorithm to ensure that there is no format or printf in the near future?

+4
source share
2 answers

There is a thing called “half to even” or “round half to odd” ( link ).

, boost::format, , ​​. , (, 1,5 2,5) ( ). , . "" , , -, round.

, , boost::format ( ), IEEE 754.

+7

, , ++ , Boost, ++ std::rint, , ++ 11 ( ) ++.

pre-++ 11, C, C rintf, rint rintl, , .

0

Source: https://habr.com/ru/post/1685310/


All Articles