Define a Unit
Understanding units
Units can be simple, like in 4 apples
.
Yet, sometimes you need to express units in regards to another unit.
For example, miles per hour is a speed expressing the number of miles travelled in exactly one hour.
Decipad will simplify units for you when possible:
Note: in the example above we're using variables to hold values. To declare a variable and assign it a value you can type
variable_name = value
.
The same goes for division:
Converting between units
Simple units
Decipad understands some basic units. To convert between them you can use the in
directive like this:
Since Decipad understands unit multipliers (deca
mili
, centi
, h
, k
), you can use them as unit prefixes:
Complex units
You can also convert more complex units. For instance, you may have the number of bananas per unit of area, and you wish to convert to the number of bananas per another unit of area:
Or, with more known units:
Expanding and contracting units
Decipad can contract and expand units automatically. For instance, pressure is force divided by area. So Decipad understands this and tries to do the right thing when you mix these units in conversions:
Or in operations:
Decipad will even auto-convert units when you need the same units for some non-numeric operations:
Conversion factors
In Decipad the following
is the same as
Creating your own units
We don't support all units. However, you can create your own:
Proportions
Simplified units can end up as a proportion, for example:
You can even use the unit simplifier for numbers.
School children are often asked how many tens, or how many ones in a number:
Custom conversions
An interesting aspect of how units work in Deci is that you can define your units and customize conversions according to your needs.
For instance, in Decipad a cup is equivalent to 0.25 litres, which is the standard UK metric:
But different countries can have different cup sizes, so you can define a custom unit to use in conversions as you wish:
This also means that you can create your custom units:
Unit Relations
Besides a quantity, units can also have a quality.
For instance, 1 kilogram of flour
and 30 grams of sugar
are both represented by units of mass with different qualities flour
and sugar
.
You can define Qualities with the keyword of
.
An example will make things easier to grasp:
With qualities, you are able to express data relations in a more realistic way. On our example you can clearly see that for every kg of flour
you will have 75 g of butter
. Awesome right?
Here's another example: