Rounding differences on Windows vs Unix based system in sprintf

前端 未结 4 1942
天涯浪人
天涯浪人 2020-12-19 01:38

I have problem on UNIX based systems sprintf does not round up properly value.

For example

double tmp = 88888888888885.875
char out[512];
         


        
4条回答
  •  北荒
    北荒 (楼主)
    2020-12-19 02:24

    On an IEEE 754 conformant implementation, it should print 88888888888885.88 in the default rounding mode. This has nothing to do with floating point precision since the value is exactly representable; it's simply a matter of printf's rounding to 2 places after the decimal point. No idea why you're seeing 88888888888885.87 on some systems.

提交回复
热议问题