numformat-old:   Number Formatting
1 Introduction
2 Interface
make-number-displayer
display-number/  us-style
display-number/  european-style
3 History
4 Legal
2:0

numformat-old: Number Formatting🔗ℹ

Neil Van Dyke

1 Introduction🔗ℹ

The numformat-old package contains some old and highly-questionable Scheme number-formatting code, which happens to still be used. Do not use this for anything important. A better modern Racket implementation of this functionality should be done.

2 Interface🔗ℹ

procedure

(make-number-displayer specs)

  (-> number? (output-port? (current-output-port)) void?)
  specs : (listof (cons/c symbol? any/c))
Make a procedure that displays numbers to output ports using formatting that is customized by the alist in specs.
> (define display-dollars-and-cents
    (make-number-displayer
     '((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 69.1)

Outputs:

 $69.10

> (display-dollars-and-cents -987654321.6969697)

Outputs:

 ($987,654,321.69)

procedure

(display-number/us-style num out)  void?

  num : number?
  out : (current-output-port)
(display-number/european-style num out)  void?
  num : number?
  out : (current-output-port)
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)

Outputs:

 -987,654,321.6969697

> (display-number/european-style x)

Outputs:

 -987 654 321,6969697

3 History🔗ℹ

4 Legal🔗ℹ

Copyright 2011, 2016 Neil Van Dyke. This program is Free 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, 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.