UNITS - Convert between units
A module that can be used to convert between various units, e.g. kg
to g
.
Synopsis
verbatim scm,8
> (require (planet "units.scm" ("oesterholt" "ho-utils.plt" 1 0))) > (define a 100) > (unit-convert a 'kg 'g) 100000 > (unit-convert a 'g 'kg) 1/10 > (require (planet "units.scm" ("oesterholt" "ho-utils.plt" 1 0))) > (define a 100) > (unit-convert a 'kg 'g) 100000 > (unit-convert a 'kg 'g) 100000 > (unit-convert a 'l '(dl cl ml) 100) dl 1000 > (unit-convert a 'l '(dl cl ml) 10000) cl 10000 > (unit-convert a 'l '(dl cl ml) 10001) ml 100000 > (unit-convert a 'l '(dl cl ml)) dl 1000 > > (unit-convert->string a 'l '(dl cl ml)) "1000dl" > (unit-convert->string a 'l '(dl cl ml) 10000) "10000cl" > > (define a 123.0) > (unit-convert->string a 'ml '(dl cl ml)) "1.23dl" > > (define a 1235.2342) > (unit-convert->rounded->string a 'ml '(dl cl ml) 3) "12.352dl" > (unit-convert->rounded->string a 'ml '(dl cl ml) 2) "12.35dl" > (unit-convert->rounded->string a 'ml '(dl cl ml) 1) "12.4dl" > (unit-convert->rounded->string a 'ml '(dl cl ml) 1 15) "123.5cl" >
> (unit-convert->rounded->string a 'ml 'cl 3) "123.523cl"
API
(unit-convert A from-unit to-unit(s) . threshold) : number | (values symbol number)
Converts A
from from-unit
to to-unit
or one of to-units
. It targets
for the minimal number, bigger then threshold
(which defaults to 1 if not given).
to-units
is a list of units.
Returns the converted A, if to-unit
is only one unit. Returns the unit A
is converted to and the converted A, if to-units
is a list
of units.
(unit-convert->string A from-unit to-unit(s) . threshold) : string
Calls unit-convert
and makes a string of the result of unit-convert
. See synopsis
for more info.
(unit-convert->rounded->string A from-unit to-unit(s) decimals . threshold) : string
Calls unit-convert
, rounds the result to decimals
decimals and makes a
string of the result, like unit-convert->string
does.
Supported Units
Currently supported unit conversions.
| computermemory | b (byte), kb (kilobyte), mb (megabyte), gb (gigabyte), tb (terabyte) | time | w (week), d (day), h (hour), m (minute), s (second), ms (millisecond), mus (microsecond), ns (nanosecond) | mass | g (gram), kg (kilogram) | distance | m (meter), dm (decimeter), cm (centimeter), mm (millimeter), km (kilometer) | contents | l (liter), dl (deciliter), cl (centiliter), ml (milliliter)
Info
(c) 2005 Hans Oesterholt-Dijkema. Distributed undef LGPL. Contact: send email to hans in domain elemental-programming.org. Homepage: http://www.elemental-programming.org.