1 Introduction
2 Interface
display-number/ us-style
display-number/ european-style
3 History
4 Legal
Version: 0.1

numformat: Sketchy Number Formatting in Racket

Neil Van Dyke

License: LGPL 3   Web: http://www.neilvandyke.org/racket-numformat/

 (require (planet neil/numformat:1:=0))

1 Introduction

Warning: This package is known to be incomplete, and probably has bugs.

The numformat package is for writing formatted numbers from Racket. As the author recalls, he started writing this package in R5RS Scheme many years ago, did not finish it, then had an urgent need for writing formatted numbers from Racket in a small personal script, and so this incomplete package was pressed into service. The author has not used this code in software developed for consulting clients. However, since people have asked over the years for better number formatting from Racket, and this package might be of assistance, the author finally decided to release this package despite its relatively poor quality. Anyone using this package should pay especially attention to the “without any warranty” part of the legal notices for this package, since, should any person attempt to sue the author over this package, the author’s armada of lawyers will just laugh and laugh at that person. Documentation is sparse.

2 Interface

(make-number-displayer specs)  any/c
  specs : any/c

Define a procedure that displays numbers to output ports using formatting that is customized by the alist in specs.

(define display-dollars-and-cents
   '((sign                   parens)
     (prefix                 "$")
     (pad-whole-char         #f)
     (pad-whole-length       #f)
     (whole-spacers-char     #\,)
     (whole-spacers-interval 3)
     (decimal-point          #\.)
     (max-fractional-length  2)
     (pad-fractional-char    #\0)
     (pad-fractional-length  2)
     (suffix                 #f))))
(display-dollars-and-cents -987654321.6969697)
(display-dollars-and-cents 69.01)
(display-dollars-and-cents 69.1)





For the possible values in specs, until those are documented, you’ll have to look at the source code, or experiment.

(display-number/us-style num out)  any/c
  num : any/c
  out : any/c

(display-number/european-style num out)  any/c
  num : any/c
  out : any/c

Write number num to output port out, using some formatting conventions of a particular locale. If out is not given, defaults to the value of (current-output-port).

For example:

(define x -987654321.6969697)
(display-number/us-style x)
(display-number/european-style x)




3 History

4 Legal

Copyright (c) 2011 Neil Van Dyke. This program is Software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License (LGPL 3), or (at your option) any later version. This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. See http://www.gnu.org/licenses/ for details. For other licenses and consulting, please contact the author.

Standard Documentation Format Note: The API signatures in this documentation are likely incorrect in some regards, such as indicating type any/c for things that are not, and not indicating when arguments are optional. This is due to a transitioning from the Texinfo documentation format to Scribble, which the author intends to finish someday.