Introduction
The Converter object provides a set of unit converters that can be used to convert between common measurement systems (metric, imperial/US customary, and scientific units where appropriate).
The design is intentionally modular: the Converter object is a container, and each converter is accessed as a
sub-object (for example, $converter->distance()).
Each converter follows the same pattern:
- Call
set_value(number value, string type) to set the input value and unit. - Call
to_*() to convert into your desired unit. - The conversion functions return a number (
ZPENumber).
Note that this object was updated and expanded on 22/02/2026 using AI to add more conversion tools rapidly. This documentation was subsequently updated using AI also.
Usage
The Converter object is used by selecting a converter and then performing a conversion:
$converter = new Converter() // Convert 5 miles to kilometres $km = $converter->distance()->set_value(5, "mi")->to_kilometres() print($km) // Convert 10 stone to kilograms $kg = $converter->mass()->set_value(10, "st")->to_kilograms() print($kg)
Converter object functions
The following is a list of internal functions the Converter object exposes. All functions are ZPEObjectNativeFunctions unless specified therefore run in native code.
-
distance() ⇒ DistanceConverter - Returns the distance/length converter (metres, kilometres, miles, yards, feet, inches, nautical miles, and more).
-
mass() ⇒ MassConverter - Returns the mass/weight converter (kilograms, grams, pounds, ounces, stone, tonnes, and more).
-
temperature() ⇒ TemperatureConverter - Returns the temperature converter (Celsius, Fahrenheit, Kelvin).
-
area() ⇒ AreaConverter - Returns the area converter (m², km², hectares, acres, ft², and more).
-
volume() ⇒ VolumeConverter - Returns the volume converter (litres, millilitres, cubic metres, gallons, pints, and more).
-
energy() ⇒ EnergyConverter - Returns the energy converter (joules, kilojoules, watt-hours, kilowatt-hours, calories, and more).
-
time() ⇒ TimeConverter - Returns the time converter (seconds, minutes, hours, days, weeks, and more).
-
speed() ⇒ SpeedConverter - Returns the speed converter (m/s, km/h, mph, knots, and more).
-
frequency() ⇒ FrequencyConverter - Returns the frequency converter (Hz, kHz, MHz, GHz, THz).
-
fuel_economy() ⇒ FuelEconomyConverter - Returns the fuel economy converter (mpg UK, mpg US, L/100km, km/L).
Converter objects
Each converter object provides set_value and a set of to_* methods.
Converter objects store the last value and unit you provided.
DistanceConverter
Converts between common distance/length units using metres as an internal base unit.
-
set_value(number value, string type) ⇒ DistanceConverter -
Sets the input value and unit. The unit may be provided in short form (
km,mi,ft) or common names ("kilometres","miles","feet"). to_metres() ⇒ numberto_kilometres() ⇒ numberto_centimetres() ⇒ numberto_millimetres() ⇒ numberto_micrometres() ⇒ numberto_nanometres() ⇒ numberto_picometers() ⇒ numberto_miles() ⇒ numberto_yards() ⇒ numberto_feet() ⇒ numberto_inches() ⇒ numberto_nautical_miles() ⇒ number- Converts the currently configured value into the chosen output unit.
Supported input units include:
m, km, cm, mm, um/µm, nm, pm,
mi, yd/yr, ft, in, nmi.
MassConverter
Converts between mass/weight units using kilograms as an internal base unit.
-
set_value(number value, string type) ⇒ MassConverter -
Sets the input value and unit. Accepts common aliases such as
"kg","grams","lb","stone","tonne", etc. to_kilograms() ⇒ numberto_grams() ⇒ numberto_milligrams() ⇒ numberto_micrograms() ⇒ numberto_pounds() ⇒ numberto_ounces() ⇒ numberto_stone() ⇒ numberto_tonnes() ⇒ numberto_us_tons() ⇒ numberto_uk_tons() ⇒ number- Converts the currently configured value into the chosen output unit.
Supported input units include:
kg, g, mg, ug/µg,
lb/lbs, oz, st,
t, ton_us, ton_uk.
TemperatureConverter
Converts between temperatures using Kelvin as an internal base unit.
-
set_value(number value, string type) ⇒ TemperatureConverter -
Sets the input temperature and unit. Accepts
"c","f","k", and common names such as"celsius","fahrenheit","kelvin". The degree symbol is accepted and ignored (for example"°c"). to_celsius() ⇒ numberto_fahrenheit() ⇒ numberto_kelvin() ⇒ number
AreaConverter
Converts between area units using square metres (m²) as an internal base unit.
-
set_value(number value, string type) ⇒ AreaConverter -
Sets the input area and unit. Units may be entered as
m2,m^2, orm², and the converter will normalise these. to_square_metres() ⇒ numberto_square_kilometres() ⇒ numberto_square_centimetres() ⇒ numberto_square_millimetres() ⇒ numberto_hectares() ⇒ numberto_ares() ⇒ numberto_square_inches() ⇒ numberto_square_feet() ⇒ numberto_square_yards() ⇒ numberto_acres() ⇒ numberto_square_miles() ⇒ number
Supported input units include: m2, cm2, mm2, km2,
ha, a, in2, ft2, yd2, acre, mi2.
VolumeConverter
Converts between common volume units using litres as an internal base unit.
-
set_value(number value, string type) ⇒ VolumeConverter -
Sets the input value and unit. Accepts common aliases such as
l,ml,m3,cm3,gal,qt,pt,floz, etc (depending on implementation). to_litres() ⇒ numberto_millilitres() ⇒ numberto_cubic_metres() ⇒ numberto_cubic_centimetres() ⇒ numberto_us_gallons() ⇒ numberto_us_quarts() ⇒ numberto_us_pints() ⇒ numberto_us_fluid_ounces() ⇒ numberto_uk_gallons() ⇒ numberto_uk_quarts() ⇒ numberto_uk_pints() ⇒ numberto_uk_fluid_ounces() ⇒ number- Converts the currently configured value into the chosen output unit.
Supported input units (typical): l, ml, m3, cm3, us_gal, uk_gal,
qt, pt, floz.
EnergyConverter
Converts between energy units using joules as an internal base unit.
-
set_value(number value, string type) ⇒ EnergyConverter -
Sets the input value and unit. Accepts common aliases such as
j,kj,wh,kwh,cal,kcal,btu(depending on implementation). to_joules() ⇒ numberto_kilojoules() ⇒ numberto_watt_hours() ⇒ numberto_kilowatt_hours() ⇒ numberto_calories() ⇒ numberto_kilocalories() ⇒ numberto_btu() ⇒ number- Converts the currently configured value into the chosen output unit.
Supported input units (typical): j, kj, wh, kwh, cal, kcal, btu.
TimeConverter
Converts between time units using seconds as an internal base unit.
-
set_value(number value, string type) ⇒ TimeConverter -
Sets the input value and unit. Accepts common aliases such as
s,sec,min,h,day, etc. to_seconds() ⇒ numberto_minutes() ⇒ numberto_hours() ⇒ numberto_days() ⇒ numberto_weeks() ⇒ numberto_months() ⇒ numberto_years() ⇒ number- Converts the currently configured value into the chosen output unit.
Supported input units (typical): s, min, h, day, week, month, year.
SpeedConverter
Converts between speed units using metres per second (m/s) as an internal base unit.
-
set_value(number value, string type) ⇒ SpeedConverter -
Sets the input value and unit. Accepts common aliases such as
m/s,km/h,mph,knot. to_metres_per_second() ⇒ numberto_kilometres_per_hour() ⇒ numberto_miles_per_hour() ⇒ numberto_knots() ⇒ number- Converts the currently configured value into the chosen output unit.
Supported input units (typical): m/s, km/h, mph, kt/knot.
FrequencyConverter
Converts between frequency units using Hertz (Hz) as an internal base unit.
-
set_value(number value, string type) ⇒ FrequencyConverter -
Sets the input value and unit. Accepts aliases such as
hz,khz,mhz,ghz,thz. to_hz() ⇒ numberto_khz() ⇒ numberto_mhz() ⇒ numberto_ghz() ⇒ numberto_thz() ⇒ number- Converts the currently configured value into the chosen output unit.
Supported input units (typical): hz, khz, mhz, ghz, thz.
FuelEconomyConverter
Converts between fuel economy units. This converter is useful because UK mpg and US mpg are not the same.
-
set_value(number value, string type) ⇒ FuelEconomyConverter -
Sets the input value and unit. Typical unit identifiers:
mpg_uk,mpg_us,l_per_100km,km_per_l. to_mpg_uk() ⇒ numberto_mpg_us() ⇒ numberto_l_per_100km() ⇒ numberto_km_per_l() ⇒ number- Converts the currently configured value into the chosen output unit.
Supported input units (typical):
mpg_uk, mpg_us, l/100km, l_per_100km, km/l, km_per_l.
Notes and caveats
-
Converter objects are designed to be chained.
set_valuereturns the converter instance so you can call ato_*method immediately afterwards. -
Units are normalised internally. For example, the area converter accepts
m²,m^2, andm2. -
If an unknown unit type is provided to
set_value, conversions may return0depending on the converter implementation. - Data rate: if you previously had a data rate converter and removed it due to stability issues, it is intentionally not documented here.
-
Remember: to create a Map in YASS you should use
[=>], notnew Map().

There are no comments on this page.
Comments are welcome and encouraged, including disagreement and critique. However, this is not a space for abuse. Disagreement is welcome; personal attacks, harassment, or hate will be removed instantly. This site reflects personal opinions, not universal truths. If you can’t distinguish between the two, this probably isn’t the place for you. The system temporarily stores IP addresses and browser user agents for the purposes of spam prevention, moderation, and safeguarding. This data is automatically removed after fourteen days. Your email address is stored so that replies can be sent to your email address.
Comments powered by BalfComment