caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Data type representing 'Money'
@ 2009-05-16  7:27 Conglun Yao
  2009-05-17  2:23 ` [Caml-list] " Edgar Friendly
  0 siblings, 1 reply; 5+ messages in thread
From: Conglun Yao @ 2009-05-16  7:27 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 317 bytes --]

Hi all,

Is there any data type could be used to represent 'Money'  in OCaml, similar
to BigDecimal.
I see a lot of programs using float directly. Maybe Num would be better, but
less document could be found, for example, how to represent 20.27

Or there already exist a better solution. Thanks for any help.

Conglun

[-- Attachment #2: Type: text/html, Size: 355 bytes --]

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

* Re: [Caml-list] Data type representing 'Money'
  2009-05-16  7:27 Data type representing 'Money' Conglun Yao
@ 2009-05-17  2:23 ` Edgar Friendly
  2009-05-17  7:10   ` Florent.Ouchet
  2009-05-17 11:29   ` Richard Jones
  0 siblings, 2 replies; 5+ messages in thread
From: Edgar Friendly @ 2009-05-17  2:23 UTC (permalink / raw)
  To: Conglun Yao, caml-list

Conglun Yao wrote:
> Hi all,
> 
> Is there any data type could be used to represent 'Money'  in OCaml,
> similar to BigDecimal.
> I see a lot of programs using float directly. Maybe Num would be better,
> but less document could be found, for example, how to represent 20.27
> 
> Or there already exist a better solution. Thanks for any help.
> 
> Conglun
> 
> 
I'd do fixed point math using Num to count cents (or mills if you really
need) but displaying dollars and cents.  For example: $20.27 would
internally be represented by the number 2027, and use int arithmetic for
exact math.

If you used 63-bit ints, you'd probably get away with not even using
Num, as max_int = 4611686018427387903 would represent the dollar amount
46_116_860_184_273_879.03, just short of 50 quadrillion dollars.

E


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

* Re: [Caml-list] Data type representing 'Money'
  2009-05-17  2:23 ` [Caml-list] " Edgar Friendly
@ 2009-05-17  7:10   ` Florent.Ouchet
  2009-05-17 16:15     ` Harrison, John R
  2009-05-17 11:29   ` Richard Jones
  1 sibling, 1 reply; 5+ messages in thread
From: Florent.Ouchet @ 2009-05-17  7:10 UTC (permalink / raw)
  To: caml-list

Hi,

Fixed point computing is okay, but the financial world used to play  
with 5 fractional digits.

Florent

"Edgar Friendly" <thelema314@gmail.com> a écrit :
> Conglun Yao wrote:
>> Hi all,
>>
>> Is there any data type could be used to represent 'Money'  in OCaml,
>> similar to BigDecimal.
>> I see a lot of programs using float directly. Maybe Num would be better,
>> but less document could be found, for example, how to represent 20.27
>>
>> Or there already exist a better solution. Thanks for any help.
>>
>> Conglun
>>
>>
> I'd do fixed point math using Num to count cents (or mills if you really
> need) but displaying dollars and cents.  For example: $20.27 would
> internally be represented by the number 2027, and use int arithmetic for
> exact math.
>
> If you used 63-bit ints, you'd probably get away with not even using
> Num, as max_int = 4611686018427387903 would represent the dollar amount
> 46_116_860_184_273_879.03, just short of 50 quadrillion dollars.
>
> E
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>


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

* Re: [Caml-list] Data type representing 'Money'
  2009-05-17  2:23 ` [Caml-list] " Edgar Friendly
  2009-05-17  7:10   ` Florent.Ouchet
@ 2009-05-17 11:29   ` Richard Jones
  1 sibling, 0 replies; 5+ messages in thread
From: Richard Jones @ 2009-05-17 11:29 UTC (permalink / raw)
  To: Edgar Friendly; +Cc: Conglun Yao, caml-list

On Sat, May 16, 2009 at 09:23:04PM -0500, Edgar Friendly wrote:
> Conglun Yao wrote:
> > Hi all,
> > 
> > Is there any data type could be used to represent 'Money'  in OCaml,
> > similar to BigDecimal.
> > I see a lot of programs using float directly. Maybe Num would be better,
> > but less document could be found, for example, how to represent 20.27
> > 
> > Or there already exist a better solution. Thanks for any help.
> > 
> > Conglun
> > 
> > 
> I'd do fixed point math using Num to count cents (or mills if you really
> need) but displaying dollars and cents.  For example: $20.27 would
> internally be represented by the number 2027, and use int arithmetic for
> exact math.
> 
> If you used 63-bit ints, you'd probably get away with not even using
> Num, as max_int = 4611686018427387903 would represent the dollar amount
> 46_116_860_184_273_879.03, just short of 50 quadrillion dollars.

But be careful if you want to use the software on 32 bit machines.
You won't even be able to represent a single mortgage loss, nevermind
the size of your bailout!

Rich.

-- 
Richard Jones
Red Hat


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

* RE: [Caml-list] Data type representing 'Money'
  2009-05-17  7:10   ` Florent.Ouchet
@ 2009-05-17 16:15     ` Harrison, John R
  0 siblings, 0 replies; 5+ messages in thread
From: Harrison, John R @ 2009-05-17 16:15 UTC (permalink / raw)
  To: caml-list; +Cc: Harrison, John R

The recent revision of the IEEE Standard 754 for binary floating-point
arithmetic added specifications for decimal floating-point types,
specifically designed for use in financial applications. In the long
term, OCaml support for these may be a good idea.

Intel provides a library with a fairly portable software implementation
of the new decimal types here:

http://software.intel.com/en-us/articles/intel-decimal-floating-point-math-library/

And if you want to find out more about decimal arithmetic, there are
several talks and a special session on the subject at this year's
Computer Arithmetic conference, the early registration deadline for
which is tomorrow :-)

http://www.ac.usc.es/arith19/

John.


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

end of thread, other threads:[~2009-05-17 16:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-16  7:27 Data type representing 'Money' Conglun Yao
2009-05-17  2:23 ` [Caml-list] " Edgar Friendly
2009-05-17  7:10   ` Florent.Ouchet
2009-05-17 16:15     ` Harrison, John R
2009-05-17 11:29   ` Richard Jones

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).