caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* What library to use for arbitrary precision decimals
@ 2006-02-19 10:18 Richard Jones
  2006-02-19 14:03 ` [Caml-list] " Christophe TROESTLER
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Jones @ 2006-02-19 10:18 UTC (permalink / raw)
  To: caml-list


What library / type should I be using for arbitrary precision decimals
- ie. floats where I can store things like currency amounts without
getting rounding errors?

Rich.

-- 
Richard Jones, CTO Merjis Ltd.
Merjis - web marketing and technology - http://merjis.com
Team Notepad - intranets and extranets for business - http://team-notepad.com


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] What library to use for arbitrary precision decimals
  2006-02-19 10:18 What library to use for arbitrary precision decimals Richard Jones
@ 2006-02-19 14:03 ` Christophe TROESTLER
  0 siblings, 0 replies; 3+ messages in thread
From: Christophe TROESTLER @ 2006-02-19 14:03 UTC (permalink / raw)
  To: Richard Jones; +Cc: OCaml Mailing List

On Sun, 19 Feb 2006, Richard Jones <rich@annexia.org> wrote:
> 
> What library / type should I be using for arbitrary precision decimals
> - ie. floats where I can store things like currency amounts without
> getting rounding errors?

For some time I have been thinking to implement the following
spec. but I never found the time...

http://72.14.207.104/search?q=cache:H663GV4FII4J:www2.hursley.ibm.com/decimal/+decimal+arithmetic&hl=en&ct=clnk&cd=1

Cheers,
ChriS


^ permalink raw reply	[flat|nested] 3+ messages in thread

* What library to use for arbitrary precision decimals
@ 2006-02-19 13:43 Joshua Smith
  0 siblings, 0 replies; 3+ messages in thread
From: Joshua Smith @ 2006-02-19 13:43 UTC (permalink / raw)
  To: caml-list

There are a couple of ways to handle money transactions without
rounding errors.

You could use the Nums library, which provides arbitrary precision
calculations and numbers.   But even with arbitrary precision numbers,
you still can have the situation where you get 405.0345 which if this
were USD, you would still have to round if you wanted to pay someone
this amount.  You will still have the arbitrary precision this way,
however.

The best way to handle money (in my experience) is to use integers. 
Then you can define conversion functions but only have to convert it
to decimal for display purposes.  That way, even if you do a million
transactions you won't lose any information.   You can also handle
non-decimal based currencies/instruments/transactions that way[1]

HTH

-jbs

[1] yes,  there are a (thank god shrinking number) of commodities and
stuff like that in the world that don't use decimal prices.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-02-19 14:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-19 10:18 What library to use for arbitrary precision decimals Richard Jones
2006-02-19 14:03 ` [Caml-list] " Christophe TROESTLER
2006-02-19 13:43 Joshua Smith

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).