On Sat, 23 Jan 2021 23:03:39 +0100, Björn Lundin wrote:
> Den 2021-01-04 kl. 04:17, skrev The Natural Philosopher:
>> On 03/01/2021 19:15, Charlie Gibbs wrote:
>>> On 2021-01-03, Joe wrote:
>>>
>>>> On Sun, 03 Jan 2021 15:41:04 GMT Jan Panteltje
>>>> wrote:
>>>>
>>>>> I use an asm math library written by someone else,
>>>>> so far 32 bit integer was all I needed,
>>>>
>>>> "If you need to use floating-point arithmetic in FORTH,
>>>> you do not fully understand your application"
>>>>
>>>> Not sure if it was Charles Moore or Leo Brodie who said that.
>>>
>>> It makes sense, though, depending on your applications.
>>> In 50 years of commercial programming, I can count the number of times
>>> I've used floating point on the fingers of one hand.
>>>
>> Odd. I use it extensively. Not for money oriented stuff tho
>>
>>
> Money should use Fixed type.
> <https://en.wikipedia.org/wiki/Fixed-
point_arithmetic#Computer_language_implementations>
Depends: Thats OK for a single currency system, but if you need to handle
multi-currency, then you need at least three variables to describe a
financial amount:
long int value;
int decimalPlace;
String currencyName;
where value is the value in the smallest legal unit (pence for GBP, cents
for Euros or dollars and decimalPlace (2 for GBP and most other
currencies, though IIRC there are a few that use 3 decilal places, is
only used when converting to or from human-readable strings.
In practise you may need quite a complex currency parser, because a lot
of bankers and finance traders would expect the system to understand,
say, USD1.5M as meaning "$1,500,000.00 US" and would expect to use that
shorthand notation when entering payment details and to get the amount
displayed the same way if they need to amend it later.
====
And yet, way back when having a PC with an 8086 in it was a sign of
status, and PC financial programs where written in BASIC, the use of
floating point for financial values was fairly common - but only because
a 16 bit signed integer topped out at a mere GBP 327.68 OR were achingly
slow because they had to use BCD or decimal encoded monetary values.
The Mainframes I've worked on have ALWAYS used integers for financial
values, though quite a lot of the weedier bottom-of-the-range IBM boxes
used BCD - but at least they had BCD hardware and didn't have to do
calculations entirely in software.
--
--
Martin | martin at
Gregorie | gregorie dot org
--- SoupGate-Win32 v1.05
* Origin: Agency HUB, Dunedin - New Zealand | FidoUsenet Gateway (3:770/3)
|