Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #83539
| From | Sams Lara <samlara622@gmail.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Adjusting printf() rounding |
| Date | 2022-04-08 18:48 +0100 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <t2psnc$19rm$1@gioia.aioe.org> (permalink) |
| References | <t2pag0$eab$1@dont-email.me> <t2pnek$3f5em$1@gwaiyur.mb-net.net> <t2podd$ubk$1@dont-email.me> |
On 08/04/2022 17:38, Paavo Helde wrote:
>
> I'm not concerned about the last (16-th) digit at all. In this case,
> I'm concerned about the third digit.
>
> printf("%.3g\n", 212.5) yields 212 in Linux and 213 on Windows.
>
> Even if we could swallow it ourselves, it would be hard to explain our
> customers why our software works inconsistently cross platform.
I am getting 212 on Windows 11 as well 64 bit:
#include <stdio.h>
int main(void)
{
printf("%0.3g\n", 212.5);
printf("%0.3g\n", 213.5);
printf("%0.3g\n", 214.5);
printf("%0.3g\n", 215.5);
return 0;
/* Output in Windows 11 using Visual Studio 2022
212
214
214
216
*/
}
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Adjusting printf() rounding Paavo Helde <eesnimi@osa.pri.ee> - 2022-04-08 15:40 +0300
Re: Adjusting printf() rounding Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2022-04-08 06:02 -0700
Re: Adjusting printf() rounding Marcel Mueller <news.5.maazl@spamgourmet.org> - 2022-04-08 18:21 +0200
Re: Adjusting printf() rounding Paavo Helde <eesnimi@osa.pri.ee> - 2022-04-08 19:38 +0300
Re: Adjusting printf() rounding Sams Lara <samlara622@gmail.com> - 2022-04-08 18:48 +0100
Re: Adjusting printf() rounding Paavo Helde <eesnimi@osa.pri.ee> - 2022-04-08 23:44 +0300
Re: Adjusting printf() rounding Marcel Mueller <news.5.maazl@spamgourmet.org> - 2022-04-09 12:58 +0200
Re: Adjusting printf() rounding Geoff <geoff@invalid.invalid> - 2022-04-09 08:45 -0700
Re: Adjusting printf() rounding Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-04-09 13:05 -0700
Re: Adjusting printf() rounding red floyd <no.spam.here@its.invalid> - 2022-04-09 13:36 -0700
Re: Adjusting printf() rounding Andrey Tarasevich <andreytarasevich@hotmail.com> - 2022-04-09 16:08 -0700
Re: Adjusting printf() rounding Manfred <noname@add.invalid> - 2022-04-08 21:30 +0200
Re: Adjusting printf() rounding "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2022-04-09 10:11 +0200
Re: Adjusting printf() rounding Paavo Helde <eesnimi@osa.pri.ee> - 2022-04-10 16:39 +0300
Re: Adjusting printf() rounding Sams Lara <samlara622@gmail.com> - 2022-04-10 18:36 +0100
Re: Adjusting printf() rounding Paavo Helde <eesnimi@osa.pri.ee> - 2022-04-10 21:50 +0300
Re: Adjusting printf() rounding Andrey Tarasevich <andreytarasevich@hotmail.com> - 2022-04-09 09:05 -0700
Re: Adjusting printf() rounding Andrey Tarasevich <andreytarasevich@hotmail.com> - 2022-04-09 09:10 -0700
csiph-web