<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.6000.16414" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV>In my opinion, Scheme provides a very good numerical system. May be this
can help you:</DIV>
<DIV> </DIV>
<DIV>(module currency->string
mzscheme<BR>
<BR> (read-decimal-as-inexact #f)</DIV>
<DIV> </DIV>
<DIV> (define (currency->string x)<BR> (let-values
<BR> (((integer-part fraction)<BR>
(quotient/remainder (* 100 x) 100)))<BR>
(string-append<BR> (number->string
integer-part)<BR> "."<BR> (number->string
fraction))))<BR> <BR> (provide currency->string))</DIV>
<DIV> </DIV>
<DIV>(module use-currency->string mzscheme<BR> (require
currency->string)<BR> (display (let ((p (open-input-string "10.22")))
(currency->string (read p)))))</DIV>
<DIV> </DIV>
<DIV>(require use-currency->string) ; displays 10.22</DIV>
<DIV> </DIV>
<DIV>With respect to currencies make sure to use arithmetic functions that
produce exact values when given exact arguments. E.g: +, -, *, / and expt
are ok, but sqrt and log are not (in this context) You may want
to read the introduction on numbers in R5RS and to take notice of the
distinction between exact and inexact numbers.</DIV>
<DIV> </DIV>
<DIV>Best wishes, Jos Koot</DIV>
<BLOCKQUOTE
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV
style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B>
<A title=jshickey@yahoo.com href="mailto:jshickey@yahoo.com">Scott Hickey</A>
</DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=plt-scheme@list.cs.brown.edu
href="mailto:plt-scheme@list.cs.brown.edu">plt-scheme@list.cs.brown.edu</A>
</DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Monday, May 07, 2007 9:04 PM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> [plt-scheme] Is plt-scheme
appropriate for applications that usecurrency?</DIV>
<DIV><BR></DIV>I have been taking a closer look at Scheme and trying to
understand the numeric types. In nearly every language I've examined, the
default numeric representation for numbers with a decimal place is binary
floating point. Thus, asserts like *like* (actually numbers differ by
language) 1.1 + 0.1 == 1.2 fail. This obviously doesn't work well in any
application involving currency.<BR><BR>In languages like Java and Ruby, I can
get around this by explicitly declaring numbers to be of type BigDecimal. In
Groovy (<A href="http://groovy.codehaus.org">http://groovy.codehaus.org</A>)
and Rexx (<A href="http://www.rexxla.org/">http://www.rexxla.org/</A>), this
math support is there by default for numeric literals. <BR><BR>Can someone
clarify what happens in plt-scheme or Scheme in general?
TIA.<BR><BR> <BR>Scott
Hickey<BR><BR><BR><BR>_________________________________________________<BR>
For list-related administrative tasks:<BR> <A
href="http://list.cs.brown.edu/mailman/listinfo/plt-scheme">http://list.cs.brown.edu/mailman/listinfo/plt-scheme</A><BR></BLOCKQUOTE></BODY></HTML>