Article View: comp.lang.c
Article #1113Re: .5 against 0.5f
From: Keith Thompson
Date: Thu, 29 Oct 2026 12:01
Date: Thu, 29 Oct 2026 12:01
22 lines
2114 bytes
2114 bytes
makendo <makendo@makendo.invalid> writes:
>> I ordered a couple of blu-rays from amazon last week, and the
>> confirmation email had the following for the total price:
>> Total
>> 75.71000000000001 USD
>> Appears they may be using FP instead of integer fixed point
>> arithmetic
>> for pricing.
>
> And this is why you should use the lowest value denominator when
> storing monetary values -- store USD values in cents, CNY values
> in fen, EUR values in cents, etc...
[...]
That's not good enough. Discounts, sales taxes, and compound
interest can easily result in amounts that are not multiples of
one cent, which must then be rounded or truncated to the nearest
cent following whatever financial rules are in effect.
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */
Technical Details
Message-ID:
<11bvcii$3a06t$3@kst.eternal-september.org>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!kst.eternal-september.org!.POSTED!not-for-mailReferences:
<11bpvs7$1e6kc$2@dont-email.me> <11bqnvh$1np7s$1@dont-email.me> <Ue6ES.2265$y_V1.1859@fx12.iad> <11bv5o7$37qph$1@dont-email.me>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!kst.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson <Keith.S.Thompson+u@gmail.com> Newsgroups: comp.lang.c Subject: Re: .5 against 0.5f Date: Thu, 29 Oct 2026 05:01:22 -0700 Organization: None to speak of Lines: 22 Message-ID: <11bvcii$3a06t$3@kst.eternal-september.org> References: <11bpvs7$1e6kc$2@dont-email.me> <11bqnvh$1np7s$1@dont-email.me> <Ue6ES.2265$y_V1.1859@fx12.iad> <11bv5o7$37qph$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Thu, 29 Oct 2026 12:01:23 +0000 (UTC) Injection-Info: kst.eternal-september.org; logging-data="3473629"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+/9Ib1P1a5KcH0err2ZXlQ"; posting-host="6d0778e7cc40265319e665d37d9f3d3e" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:gZTQ63ffL9l8VWO2uYfPEx8STSQ= sha256:aOuT4DUT3TeeiCrn/5sEcZufgbCKjO7bIUjjOA5r820= sha1:d7Hcu1HXUfoiq81Qv6lfZ7qVpr4= sha256:s+c/FwwX/1GnJ9xwZtpvbublvjdth7ecd/7PpnmxK7A=