One widget which uses this interface is
AG_Numerical(3), which accepts
unit arguments.
The following code fragment creates a widget for editing
a length value given in meters:
float length = 1.234;
AG_Numerical *num;
num = AG_NumericalNewFlt(parent, 0, "m", "Length: ", &length)
|
The following code fragment prints the equivalent milliseconds for a given
n number of seconds:
printf("%f seconds = %f milliseconds", n,
AG_Base2Unit(n, AG_FindUnit("ms")));
|
The following code fragment prints the equivalent of 27 degrees Celsius,
in kilo Kelvins:
const AG_Unit *degC = AG_FindUnit("degC");
const AG_Unit *kk = AG_FindUnit("kk");
printf("27C = %fkk", AG_Unit2Unit(27.0, degC, kk));
|
This code fragment displays the value of
r using the resistance unit most suitable to its magnitude.
printf("Resistance = %s", AG_UnitFormat(r, agResistanceUnits));
|
Also see
tests/unitconv.c in the Agar source distribution.
|