I would like to understand why
double nbr = 102262.5; boost::format("%.0f") % nbr;
gives 102262, but round(102262.5)gives102263.0
102262
round(102262.5)
102263.0
If we take another approximate value 34087.5
34087.5
boost::format("%.0f") % nbr
gives 34088and round(34087.5)gives the same34088
34088
round(34087.5)
Does this mean that round implements a more complex algorithm to ensure that there is no format or printf in the near future?
There is a thing called “half to even” or “round half to odd” ( link ).
, boost::format, , . , (, 1,5 2,5) ( ). , . "" , , -, round.
boost::format
round
, , boost::format ( ), IEEE 754.
, , ++ , Boost, ++ std::rint, , ++ 11 ( ) ++.
std::rint
pre-++ 11, C, C rintf, rint rintl, , .
rintf
rint
rintl
Source: https://habr.com/ru/post/1685310/More articles:How can I track the progress of loading files on the back panel using Spring Boot? - javaMySQL CREATE TABLE FROM UNION gives "invalid default value" - sqlmutate_geocode (ggmap)AngularJS using the templateHtml path as the module name - angularjsWebpack: Должен ли я строить пакет на рабочем сервере или строить его локально, а затем загружать? - webpackПочему это рекурсивное регулярное выражение не захватывает весь блок кода? - regexDo web workers get their own garbage collector? - javascriptAdding a CSV row: DictWriter always writes from the first column - pythonfatal error compiling an invalid flag --module-path - javaAngular use innerHTML with escaped element attributes - angularAll Articles