Measurement units
NepaliArea, NepaliWeight and NepaliVolume convert between traditional Nepali units and metric units. All three work the same way:
- Create a value from one unit, or from mixed units:
NepaliArea.ropani(2, aana: 3). - Convert it with
to(unit). - Split it into mixed units with the
…Partsgetters. - Write it as
2-3-1-0or2 ropani 3 aana 1 paisawithformat, in English or Nepali. - Read
2-3-1-0or२-३-१-०back withparse/tryParse. - Add, subtract, multiply, divide and compare values.
Values are immutable and compare by quantity.
Land area: NepaliArea
Section titled “Land area: NepaliArea”Land in the hills is measured in ropani-aana-paisa-daam, and land in the Terai in bigha-kattha-dhur.
| Unit | Equals | Square feet | Square metres |
|---|---|---|---|
| ropani (रोपनी) | 16 aana | 5476 (74 × 74) | ≈ 508.737 |
| aana (आना) | 4 paisa | 342.25 | ≈ 31.796 |
| paisa (पैसा) | 4 daam | 85.5625 | ≈ 7.949 |
| daam (दाम) | 21.390625 | ≈ 1.987 | |
| bigha (बिघा) | 20 kattha | 72900 (270 × 270) | ≈ 6772.632 |
| kattha (कट्ठा) | 20 dhur | 3645 | ≈ 338.632 |
| dhur (धुर) | 182.25 | ≈ 16.932 |
AreaUnit also has squareFoot, squareMeter, acre and hectare.
final plot = NepaliArea.ropani(2, aana: 3, paisa: 1);
plot.to(.squareFoot); // 12064.3125plot.to(.squareMeter); // 1120.81130676plot.to(.aana); // 35.25plot.ropaniParts; // (aana: 3, daam: 0.0, paisa: 1, ropani: 2)plot.bighaParts; // (bigha: 0, dhur: 6.196502058, kattha: 3)
plot.format(.ropani); // 2-3-1-0plot.format(.ropani, long: true); // 2 ropani 3 aana 1 paisaplot.format(.ropani, long: true, language: .nepali); // २ रोपनी ३ आना १ पैसाplot.format(.bigha); // 0-3-6.2plot.format(.bigha, long: true); // 3 kattha 6.2 dhurAny unit can be converted to any other:
NepaliArea(1000, .squareMeter).format(.ropani); // 1-15-1-3.21NepaliArea.bigha(1, kattha: 5).to(.ropani); // 16.640796201607014NepaliArea(1, .acre).format(.bigha, long: true); // 11 kattha 19.01 dhurformat takes an AreaSystem: .ropani (ropani-aana-paisa-daam) or .bigha (bigha-kattha-dhur).
Weight: NepaliWeight
Section titled “Weight: NepaliWeight”Gold and silver are weighed in tola-lal, and goods in the market in dharni-ser-pau-chhatak.
| Unit | Equals | Grams |
|---|---|---|
| tola (तोला) | 100 lal | 11.6638038 |
| lal (लाल) | 0.116638038 | |
| dharni (धार्नी) | 3 ser | 2393.4096 |
| ser (सेर) | 4 pau | 797.8032 |
| pau (पाउ) | 4 chhatak | 199.4508 |
| chhatak (छटाक) | 49.8627 |
WeightUnit also has gram and kilogram. WeightSystem is .tola or .dharni.
final gold = NepaliWeight.tola(2, lal: 50);
gold.to(.gram); // 29.1595095gold.tolaParts; // (lal: 50.0, tola: 2)gold.format(.tola); // 2-50gold.format(.tola, long: true); // 2 tola 50 lalgold.format(.tola, long: true, language: .nepali); // २ तोला ५० लाल
NepaliWeight(10, .gram).format(.tola); // 0-85.74NepaliWeight(5, .kilogram).format(.dharni); // 2-0-1-0.28NepaliWeight(5, .kilogram).format(.dharni, long: true); // 2 dharni 1 pau 0.28 chhatakGrain volume: NepaliVolume
Section titled “Grain volume: NepaliVolume”Grain is measured in muri-pathi-mana-muthi.
| Unit | Equals | Litres |
|---|---|---|
| muri (मुरी) | 20 pathi | 90.9192 |
| pathi (पाथी) | 8 mana | 4.54596 |
| mana (माना) | 10 muthi | 0.568245 |
| muthi (मुठी) | 0.0568245 |
VolumeUnit also has liter. There is only one system, so format and parse don’t take one.
final rice = NepaliVolume.muri(1, pathi: 5, mana: 4);
rice.to(.pathi); // 25.5rice.to(.liter); // 115.92198rice.muriParts; // (mana: 4, muri: 1, muthi: 0.0, pathi: 5)rice.format(); // 1-5-4-0rice.format(long: true); // 1 muri 5 pathi 4 manarice.format(language: .nepali); // १-५-४-०
NepaliVolume(10, .liter).format(); // 0-2-1-5.98Formatting
Section titled “Formatting”All three format methods take the same options:
| Option | Default | Effect |
|---|---|---|
long |
false |
false gives dash-separated parts (2-3-1-0). true names the units and leaves out zero parts (2 ropani 3 aana 1 paisa). |
language |
NepaliUtils.currentLanguage |
Nepali uses Devanagari digits and unit names. |
fractionDigits |
2 |
Decimal places for the smallest unit. Rounding carries into the larger units. |
plot.format(.bigha); // 0-3-6.2plot.format(.bigha, fractionDigits: 0); // 0-3-6NepaliArea.zero.format(.ropani, long: true); // 0 daamBecause rounding carries, 15 ropani 15 aana 3 paisa 3.999 daam becomes 16-0-0-0 with 2 digits, not 15-15-3-4:
NepaliArea.ropani(15, aana: 15, paisa: 3, daam: 3.999).format(.ropani); // 16-0-0-0Unit names are available on their own through label:
AreaUnit.ropani.label(); // ropaniAreaUnit.ropani.label(.nepali); // रोपनीAreaUnit.squareMeter.label(); // sq. mWeightUnit.tola.label(.nepali); // तोलाParsing
Section titled “Parsing”parse reads dash-separated parts in ASCII or Devanagari digits. Missing parts at the end count as zero:
NepaliArea.parse('२-३-१-०', .ropani) == plot; // trueNepaliArea.parse('2-3', .ropani).format(.ropani); // 2-3-0-0NepaliArea.parse('1-5-2.5', .bigha).format(.bigha, long: true); // 1 bigha 5 kattha 2.5 dhurNepaliWeight.parse('२-५०', .tola) == gold; // trueNepaliVolume.parse('१-५-४') == rice; // true
NepaliArea.tryParse('2-x', .ropani); // nullEach part must be a non-negative decimal number, and there can’t be more parts than the system has units. Otherwise parse throws a FormatException and tryParse returns null.
Arithmetic and comparison
Section titled “Arithmetic and comparison”(plot + NepaliArea.ropani(0, aana: 13)).format(.ropani); // 3-0-1-0(plot / 2).format(.ropani); // 1-1-2-2(rice * 2).format(long: true); // 2 muri 11 pathiplot > NepaliArea.ropani(2); // true(-plot).ropaniParts; // (aana: -3, daam: 0.0, paisa: -1, ropani: -2)The operators +, -, * (by a number), / (by a number), unary -, <, <=, > and >= are supported, and compareTo too. Values implement Comparable, so lists of them can be sorted.
Precision
Section titled “Precision”Every value is stored in one base unit: square feet for area, grams for weight and litres for volume. Every ropani and bigha unit is a whole multiple of 1/64 square foot. So conversions between those units, square feet and acres are exact. Conversions through square metres, hectares or other metric units are rounded like any double:
NepaliWeight.dharni(1, ser: 2).to(.kilogram); // 3.9890159999999995Round the result for display, or use format, which rounds the smallest unit for you.
