[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Proposed new FORMAT operator: ~U("units")

Here's a krevitch that will really snork your flads.  ~U swallows
an argument, which should be a floating-point number (an integer or
ratio may be floated first).  The argument is then scaled by 10^(3*K)
for some integer K, so that it lies in [1.0,1000.0).  If this
K is suitably small, then the scaled number is printed, then a space,
then a metric-system prefix.  If not, then the number is printed
in exponential notation, then a space.  With a :, prints the short prefix.
 (FORMAT () "~Umeters, ~Uliters, ~:Um, ~:UHz" 50300.0 6.0 .013 1.0e7)
  =>  "50.5 kilometers, 6.0 liters, 13.0 mm, 10.0 MHz"

And you thought ~R was bad!