### Documentation for the "NumberFormatter" class.

*Used by CIDRAM and phpMussel to format numbers generated by their front-end pages, the class provides a more controllable, customisable mechanism for number formatting than PHP's internal `number_format()` function.*

---


### How to use:

- [NumberFormatter constructor.](#numberformatter-constructor)
- [format method.](#format-method)
- [getSetCSV method.](#getsetcsv-method)
- [ConversionSet member.](#conversionset-member)
- [GroupSeparator member.](#groupseparator-member)
- [GroupSize member.](#groupsize-member)
- [GroupOffset member.](#groupoffset-member)
- [DecimalSeparator member.](#decimalseparator-member)
- [Base member.](#base-member)

#### NumberFormatter constructor.

```PHP
public function __construct(string $Format = '');
```

To use the number formatter, you'll firstly need to instantiate it. You don't need to parse any parameters to the constructor, but it optionally accepts one parameter, `$Format`. The `$Format` parameter can be used to immediately set various commonly used values to the object's members during object instantiation (so that you won't need to set each definition manually). You can set these later though. More information about these members will be explained later in this document. The currently supported values for `$Format` are listed in the table below.

Value | `ConversionSet` | `GroupSeparator` | `GroupSize` | `GroupOffset` | `DecimalSeparator` | `Base`
---|---|---|---|---|---|---
*Default values (e.g., when the parameter is omitted) and*  `Latin-1`. | `Western` | `,`<br />(comma) | `3` | `0` | `.`<br />(decimal) | `10`
`Arabic-1` | `Eastern` | (empty) | (n/a) | (n/a) | `٬`<br />(arabic decimal separator) | `10`
`Arabic-2` | `Eastern` | `٬`<br />(arabic thousands separator) | `3` | `0` | `٬`<br />(arabic decimal separator) | `10`
`Arabic-3` or `Persian` | `Persian` | `٬`<br />(arabic thousands separator) | `3` | `0` | `٬`<br />(arabic decimal separator) | `10`
`Arabic-4` or `Urdu` | `Persian` | `٬`<br />(arabic thousands separator) | `2` | `-1` | `٬`<br />(arabic decimal separator) | `10`
`Armenian` *[†3] [†4]* | `Armenian` | (empty) | (n/a) | (n/a) | (empty) | `10`
`Base-12` *[†2]* | `Western` | (empty) | (n/a) | (n/a) | `.`<br />(decimal) | `12`
`Base-16` *[†2]* | `Western` | (empty) | (n/a) | (n/a) | `.`<br />(decimal) | `16`
`Bengali-1` or `Nagari` | `Nagari` | `,`<br />(comma) | `2` | `-1` | `.`<br />(decimal) | `10`
`Burmese-1` | `Burmese` | (empty) | (n/a) | (n/a) | `.`<br />(decimal) | `10`
`China-1` | `Western` | `,`<br />(comma) | `4` | `0` | `.`<br />(decimal) | `10`
`Chinese-Simplified-Financial` *[†4]* | `ChineseSimplifiedFinancial` | (empty) | (n/a) | (n/a) | `点`<br />(U+70B9) | `10`
`Chinese-Simplified` *[†4]* | `ChineseSimplified` | (empty) | (n/a) | (n/a) | `点`<br />(U+70B9) | `10`
`Chinese-Traditional-Financial` *[†4]* | `ChineseTraditionalFinancial` | (empty) | (n/a) | (n/a) | `點`<br />(U+9EDE) | `10`
`Chinese-Traditional` *[†4]* | `ChineseTraditional` | (empty) | (n/a) | (n/a) | `點`<br />(U+9EDE) | `10`
`Fullwidth` | `Fullwidth` | (empty) | (n/a) | (n/a) | `.`<br />(decimal) | `10`
`Hebrew` *[†3] [†4]* | `Hebrew` | (empty) | (n/a) | (n/a) | (empty) | `10`
`India-1` | `Western` | `,`<br />(comma) | `2` | `-1` | `.`<br />(decimal) | `10`
`India-2` or `Devanagari` | `Devanagari` | `,`<br />(comma) | `2` | `-1` | `.`<br />(decimal) | `10`
`India-3` or `Gujarati` | `Gujarati` | `,`<br />(comma) | `2` | `-1` | `.`<br />(decimal) | `10`
`India-4` or `Gurmukhi` | `Gurmukhi` | `,`<br />(comma) | `2` | `-1` | `.`<br />(decimal) | `10`
`India-5` or `Kannada` | `Kannada` | `,`<br />(comma) | `2` | `-1` | `.`<br />(decimal) | `10`
`India-6` or `Telugu` | `Telugu` | `,`<br />(comma) | `2` | `-1` | `.`<br />(decimal) | `10`
`Japanese` *[†4]* | `Japanese` | (empty) | (n/a) | (n/a) | `・`<br />(katakana middle dot) | `10`
`Javanese` | `Javanese` | (empty) | (n/a) | (n/a) | `.`<br />(decimal) | `10`
`Khmer-1` | `Khmer` | `.`<br />(decimal) | `3` | `0` | `,`<br />(comma) | `10`
`Lao-1` | `Lao` | (empty) | (n/a) | (n/a) | `.`<br />(decimal) | `10`
`Latin-2` | `Western` | ` `<br />(non-breaking space) | `3` | `0` | `.`<br />(decimal) | `10`
`Latin-3` | `Western` | `.`<br />(decimal) | `3` | `0` | `,`<br />(comma) | `10`
`Latin-4` | `Western` | ` `<br />(non-breaking space) | `3` | `0` | `,`<br />(comma) | `10`
`Latin-5` | `Western` | `,`<br />(comma) | `3` | `0` | `·`<br />(middle dot) | `10`
`Mayan` *[†1] [†2]* | `Mayan` | (empty) | (n/a) | (n/a) | `.`<br />(decimal) | `20`
`Mongolian` | `Mongolian` | (empty) | (n/a) | (n/a) | `.`<br />(decimal) | `10`
`NoSep-1` | `Western` | (empty) | (n/a) | (n/a) | `.`<br />(decimal) | `10`
`NoSep-2` | `Western` | (empty) | (n/a) | (n/a) | `,`<br />(comma) | `10`
`Odia` | `Odia` | (empty) | (n/a) | (n/a) | `.`<br />(decimal) | `10`
`Roman` *[†3] [†4]* | `Roman` | (empty) | (n/a) | (n/a) | (empty) | `10`
`SDN-Dwiggins` | `Dwiggins` | `,`<br />(comma) | `3` | `0` | `;`<br />(semicolon) | `12`
`SDN-Pitman` | `Pitman` | `,`<br />(comma) | `3` | `0` | `;`<br />(semicolon) | `12`
`Tamil` *[†3] [†4]* | `Tamil` | (empty) | (n/a) | (n/a) | (empty) | `10`
`Thai-1` | `Thai` | `,`<br />(comma) | `3` | `0` | `.`<br />(decimal) | `10`
`Thai-2` | `Thai` | (empty) | (n/a) | (n/a) | `.`<br />(decimal) | `10`
`Tibetan` | `Tibetan` | (empty) | (n/a) | (n/a) | `.`<br />(decimal) | `10`

*[†1]: Not actually "commonly used" at all, seeing as it [hasn't actually been actively used since the 17th century](https://en.wikipedia.org/wiki/Maya_script), so, unlikely to be practical, but included anyway as a means of demonstratrating some of what the class can do (think of it as an "easter egg").*

*[†2]: The class fully supports fractions, including the ability to convert between arbitrary bases for both decimals and fractions alike, and including for numeral systems, that the class supports, that mightn't necessarily themselves support fractions natively, or in the contexts where those numeral systems would normally be used. It's not my intention to imply that they should. However, the support already exists, removing it for specific numeral systems would require additional code complexity, and doing so would be generally pointless, I think. Alternatively, any users concerned about this can easily just omit the `$Decimals` parameter when calling `format()` to avoid fractions.*

*[†3]: Fractions not supported in this context, either because fractions don't make sense in the context of the conversion set used, or because supporting fractions in this context would significantly increase code complexity.*

*[†4]: The conversion set used has a range limit (i.e., numbers outside the range limit can't be rendered or represented accurately).*

*(n/a): Means "not applicable".*

#### format method.

After instantiating the number formatter, after setting any necessary values for the instance's members, the format method is used to format numbers.

```PHP
public function format($Number, int $Decimals = 0): string;
```

The method accepts two parameters.

The first parameter, `$Number`, is the number you want to format (mandatory). The method uses this parameter in a way consistent with strings, but any scalar value (e.g., string, int, float) can be used.

The second parameter, `$Decimals`, is an optional integer (defaults to `0`), and tells the method how many decimal places you expect the formatted number to have.

Example:

```PHP
<?php
$Formats = [
    'Arabic-1',
    'Arabic-2',
    'Arabic-3',
    'Arabic-4',
    'Armenian',
    'Base-12',
    'Base-16',
    'Bengali-1',
    'Burmese-1',
    'China-1',
    'Chinese-Simplified',
    'Chinese-Simplified-Financial',
    'Chinese-Traditional',
    'Chinese-Traditional-Financial',
    'Fullwidth',
    'Hebrew',
    'India-1',
    'India-2',
    'India-3',
    'India-4',
    'India-5',
    'India-6',
    'Japanese',
    'Javanese',
    'Kaktovik',
    'Khmer-1',
    'Lao-1',
    'Latin-1',
    'Latin-2',
    'Latin-3',
    'Latin-4',
    'Latin-5',
    'Mayan',
    'Mongolian',
    'NoSep-1',
    'NoSep-2',
    'Odia',
    'Roman',
    'SDN-Dwiggins',
    'SDN-Pitman',
    'Tamil',
    'Thai-1',
    'Thai-2',
    'Tibetan'
];

echo "Format | `\$Obj->format('1234567.89', 2)` | `\$Obj->format('10203040.50607080', 5)` | `\$Obj->format('100.75', 3)`\n---|---|---|---\n";

foreach ($Formats as $Format) {
    $Obj = new \Maikuolan\Common\NumberFormatter($Format);
    echo '`' . $Format . '` | `' . $Obj->format('1234567.89', 2) . '` | `' . $Obj->format('10203040.50607080', 5) . '` | `' . $Obj->format('100.75', 3) . "`\n";
}
```

Output:

Format | `$Obj->format('1234567.89', 2)` | `$Obj->format('10203040.50607080', 5)` | `$Obj->format('100.75', 3)`
:--|--:|--:|--:
`Arabic-1` | `١٢٣٤٥٦٧٫٨٩` | `١٠٢٠٣٠٤٠٫٥٠٦٠٧` | `١٠٠٫٧٥٠`
`Arabic-2` | `١٬٢٣٤٬٥٦٧٫٨٩` | `١٠٬٢٠٣٬٠٤٠٫٥٠٦٠٧` | `١٠٠٫٧٥٠`
`Arabic-3` | `۱٬۲۳۴٬۵۶۷٫۸۹` | `۱۰٬۲۰۳٬۰۴۰٫۵۰۶۰۷` | `۱۰۰٫۷۵۰`
`Arabic-4` | `۱۲٬۳۴٬۵۶۷٫۸۹` | `۱٬۰۲٬۰۳٬۰۴۰٫۵۰۶۰۷` | `۱۰۰٫۷۵۰`
`Armenian` | `Ռ̅Մ̅Լ̅ՏՇԿԷ` | `Մ̅ՎԽ` | `Ճ`
`Base-12` | `4b6547.a8` | `3500654.60a5a` | `84.900`
`Base-16` | `12d687.e3` | `9bafa0.818dd` | `64.c00`
`Bengali-1` | `১২,৩৪,৫৬৭.৮৯` | `১,০২,০৩,০৪০.৫০৬০৭` | `১০০.৭৫০`
`Burmese-1` | `၁၂၃၄၅၆၇.၈၉` | `၁၀၂၀၃၀၄၀.၅၀၆၀၇` | `၁၀၀.၇၅၀`
`China-1` | `123,4567.89` | `1020,3040.50607` | `100.750`
`Chinese-Simplified` | `一百二十三万四千五百六十七点八九` | `一千二十三千四十点五〇六〇七` | `一百点七五〇`
`Chinese-Simplified-Financial` | `壹佰贰拾叁萬肆仟伍佰陆拾柒点捌玖` | `壹仟贰拾叁仟肆拾点伍零陆零柒` | `壹佰点柒伍零`
`Chinese-Traditional` | `一百二十三萬四千五百六十七點八九` | `一千二十三千四十點五零六零七` | `一百點七五零`
`Chinese-Traditional-Financial` | `壹佰貳拾叄萬肆仟伍佰陸拾柒點捌玖` | `壹仟貳拾叄仟肆拾點伍零陸零柒` | `壹佰點柒伍零`
`Fullwidth` | `１２３４５６７.８９` | `１０２０３０４０.５０６０７` | `１００.７５０`
`Hebrew` | `א׳׳ב׳קג׳יד׳ךסז` | `א׳י׳ב׳קג׳מ` | `ק`
`India-1` | `12,34,567.89` | `1,02,03,040.50607` | `100.750`
`India-2` | `१२,३४,५६७.८९` | `१,०२,०३,०४०.५०६०७` | `१००.७५०`
`India-3` | `૧૨,૩૪,૫૬૭.૮૯` | `૧,૦૨,૦૩,૦૪૦.૫૦૬૦૭` | `૧૦૦.૭૫૦`
`India-4` | `੧੨,੩੪,੫੬੭.੮੯` | `੧,੦੨,੦੩,੦੪੦.੫੦੬੦੭` | `੧੦੦.੭੫੦`
`India-5` | `೧೨,೩೪,೫೬೭.೮೯` | `೧,೦೨,೦೩,೦೪೦.೫೦೬೦೭` | `೧೦೦.೭೫೦`
`India-6` | `౧౨,౩౪,౫౬౭.౮౯` | `౧,౦౨,౦౩,౦౪౦.౫౦౬౦౭` | `౧౦౦.౭౫౦`
`Japanese` | `百万二十万三万四千五百六十七・八九分` | `千万二十万三千四十・五六厘七糸` | `百・七五分`
`Javanese` | `꧑꧒꧓꧔꧕꧖꧗.꧘꧙` | `꧑꧐꧒꧐꧓꧐꧔꧐.꧕꧐꧖꧐꧗` | `꧑꧐꧐.꧗꧕꧐`
`Kaktovik` | `𝋇𝋎𝋆𝋈𝋇.𝋑𝋐` | `𝋃𝋃𝋏𝋇𝋌𝋀.𝋊𝋂𝋈𝋋𝋆` | `𝋅𝋀.𝋏𝋀𝋀`
`Khmer-1` | `១.២៣៤.៥៦៧,៨៩` | `១០.២០៣.០៤០,៥០៦០៧` | `១០០,៧៥០`
`Lao-1` | `໑໒໓໔໕໖໗.໘໙` | `໑໐໒໐໓໐໔໐.໕໐໖໐໗` | `໑໐໐.໗໕໐`
`Latin-1` | `1,234,567.89` | `10,203,040.50607` | `100.750`
`Latin-2` | `1 234 567.89` | `10 203 040.50607` | `100.750`
`Latin-3` | `1.234.567,89` | `10.203.040,50607` | `100,750`
`Latin-4` | `1 234 567,89` | `10 203 040,50607` | `100,750`
`Latin-5` | `1,234,567·89` | `10,203,040·50607` | `100·750`
`Mayan` | `𝋧𝋮𝋦𝋨𝋧.𝋱𝋰` | `𝋣𝋣𝋯𝋧𝋬𝋠.𝋪𝋢𝋨𝋫𝋦` | `𝋥𝋠.𝋯𝋠𝋠`
`Mongolian` | `᠑᠒᠓᠔᠕᠖᠗.᠘᠙` | `᠑᠐᠒᠐᠓᠐᠔᠐.᠕᠐᠖᠐᠗` | `᠑᠐᠐.᠗᠕᠐`
`NoSep-1` | `1234567.89` | `10203040.50607` | `100.750`
`NoSep-2` | `1234567,89` | `10203040,50607` | `100,750`
`Odia` | `୧୨୩୪୫୬୭.୮୯` | `୧୦୨୦୩୦୪୦.୫୦୬୦୭` | `୧୦୦.୭୫୦`
`Roman` | `M̅C̅C̅X̅X̅X̅I̅V̅DLXVII` | `C̅C̅MMMXL` | `C`
`SDN-Dwiggins` | `4E6,547;X8` | `3,500,654;60X5X` | `84;900`
`SDN-Pitman` | `4↋6,547;↊8` | `3,500,654;60↊5↊` | `84;900`
`Tamil` | `௲௲௨௱௲௩௰௲௪௲௫௱௬௰௭` | `௰௲௲௨௱௲௩௲௪௰` | `௱`
`Thai-1` | `๑,๒๓๔,๕๖๗.๘๙` | `๑๐,๒๐๓,๐๔๐.๕๐๖๐๗` | `๑๐๐.๗๕๐`
`Thai-2` | `๑๒๓๔๕๖๗.๘๙` | `๑๐๒๐๓๐๔๐.๕๐๖๐๗` | `๑๐๐.๗๕๐`
`Tibetan` | `༡༢༣༤༥༦༧.༨༩` | `༡༠༢༠༣༠༤༠.༥༠༦༠༧` | `༡༠༠.༧༥༠`

#### getSetCSV method.

Gets the specified conversion set and returns it as a CSV string. Not normally needed by the implementation, but can sometimes be useful if the implementation needs further work done on numbers outside the scope of the number formatter itself.

```PHP
$Obj = new \Maikuolan\Common\NumberFormatter('Javanese');
echo $Obj->getSetCSV() . PHP_EOL;
echo $Obj->getSetCSV('Roman') . PHP_EOL;
echo $Obj->getSetCSV('Persian') . PHP_EOL;
```

Output:

```
'꧐','꧑','꧒','꧓','꧔','꧕','꧖','꧗','꧘','꧙'
'','','','','','','','','','','I','II','III','IV','V','VI','VII','VIII','IX','X','XX','XXX','XL','L','LX','LXX','LXXX','XC','C','CC','CCC','CD','D','DC','DCC','DCCC','CM','M','MM','MMM'
'۰','۱','۲','۳','۴','۵','۶','۷','۸','۹'
```

#### ConversionSet member.

```PHP
public $ConversionSet = 'Western';
```

The ConversionSet member tells the number formatter which characters it should to use to represent which numbers.

Currently supported values:

Value | Description
---|---
`Western` | Standard numerals (0-9), alternatively known as Western Arabic numerals, Arabic numerals, Hindu-Arabic numerals, etc.
`Armenian` | Armenian numerals. *(Fractions not supported. Range limit: 1 ~ 9,999,999).*
`Burmese` | Burmese numerals.
`ChineseSimplifiedFinancial` | Financial simplified Chinese numerals. *(Range upper limit: 10<sup>^48</sup>-1).*
`ChineseSimplified` | Standard simplified Chinese numerals. *(Range upper limit: 10<sup>^48</sup>-1).*
`ChineseTraditionaFinancial` | Financial traditional Chinese numerals. *(Range upper limit: 10<sup>^48</sup>-1).*
`ChineseTraditional` | Standard traditional Chinese numerals. *(Range upper limit: 10<sup>^48</sup>-1).*
`Devanagari` | Devanagari numerals.
`Eastern` | Eastern Arabic numerals.
`Fullwidth` | Fullwidth numerals.
`Gujarati` | Gujarati numerals.
`Gurmukhi` | Gurmukhi numerals.
`Hebrew` | Hebrew numerals. *(Fractions not supported. Range limit: 1 ~ 10<sup>^16</sup>-1).*
`Japanese` | Japanese numerals. *(Range limit: 10<sup>^-11</sup>+1 ~ 10<sup>^24</sup>-1).*
`Javanese` | Javanese numerals.
`Kaktovik` | Kaktovik numerals.
`Kannada` | Kannada numerals.
`Khmer` | Khmer numerals.
`Lao` | Lao numerals.
`Mayan` | Mayan numerals.
`Mongolian` | Mongolian numerals.
`Nagari` | Nagari/Bengali/Bangla numerals.
`Odia` | Odia numerals.
`OlChiki` | Ol Chiki numerals.
`Persian` | Persian/Urdu numerals (Eastern Arabic variant).
`Roman` | Roman numerals. *(Fractions not supported. Range limit: 1 ~ 3,999,999).*
`Tamil` | Tamil numerals. *(Fractions not supported. Range limit: 1 ~ 10<sup>^24</sup>-1).*
`Telugu` | Telugu numerals.
`Thai` | Thai numerals.
`Tibetan` | Tibetan numerals.

(If needed, the class can easily be extended to add support for additional conversion sets).

Example usage:

```PHP
$Obj = new \Maikuolan\Common\NumberFormatter();

$Obj->ConversionSet = 'Devanagari';
echo $Obj->format('123.45', 2) . PHP_EOL;

$Obj->ConversionSet = 'Kannada';
echo $Obj->format('123.45', 2) . PHP_EOL;

$Obj->ConversionSet = 'Western';
echo $Obj->format('123.45', 2) . PHP_EOL;
```

Output:

```
१२३.४५
೧೨೩.೪೫
123.45
```

#### GroupSeparator member.

```PHP
public $GroupSeparator = ',';
```

The GroupSeparator member tells the number formatter which character to use to separate groups of numbers (e.g., the comma in `1,234.56`).

Example usage:

```PHP
$Obj = new \Maikuolan\Common\NumberFormatter();

$Obj->GroupSeparator = "'";
echo $Obj->format('1234567.89', 2) . PHP_EOL;

$Obj->GroupSeparator = ',';
echo $Obj->format('1234567.89', 2) . PHP_EOL;

$Obj->GroupSeparator = '.';
$Obj->DecimalSeparator = ',';
echo $Obj->format('1234567.89', 2) . PHP_EOL;
```

Output:

```
1'234'567.89
1,234,567.89
1.234.567,89
```

#### GroupSize member.

```PHP
public $GroupSize = 3;
```

The GroupSize member tells the number formatter how many numbers should from a number group (typically this is three, but sometimes other sizes may be needed).

Example usage:

```PHP
$Obj = new \Maikuolan\Common\NumberFormatter();

$Obj->GroupSize = 4;
echo $Obj->format('1234567.89', 2) . PHP_EOL;

$Obj->GroupSize = 3;
echo $Obj->format('1234567.89', 2) . PHP_EOL;

$Obj->GroupSize = 2;
echo $Obj->format('1234567.89', 2) . PHP_EOL;
```

Output:

```
123,4567.89
1,234,567.89
1,23,45,67.89
```

#### GroupOffset member.

```PHP
public $GroupOffset = 0;
```

The GroupOffset member provides a mechanism by which the first number group in a number can be a different size to any subsequent number groups in the number. This can be particularly important when expressing numbers that deal with [lakhs](https://en.wikipedia.org/wiki/Lakh) and [crores](https://en.wikipedia.org/wiki/Crore), typically requiring that the first number group contain three numbers, with any subsequent number groups containing two numbers.

Example usage:

```PHP
$Obj = new \Maikuolan\Common\NumberFormatter();

$Obj->GroupOffset = -2;
echo $Obj->format('1000000000000000') . PHP_EOL;

$Obj->GroupOffset = -1;
echo $Obj->format('1000000000000000') . PHP_EOL;

$Obj->GroupOffset = 0;
echo $Obj->format('1000000000000000') . PHP_EOL;

$Obj->GroupOffset = 1;
echo $Obj->format('1000000000000000') . PHP_EOL;

$Obj->GroupOffset = 2;
echo $Obj->format('1000000000000000') . PHP_EOL;

$Obj->GroupSize = 2;
$Obj->GroupOffset = -1;
echo $Obj->format('1000000000000000') . PHP_EOL;
```

Output:

```
10,000,000,000,00000
100,000,000,000,0000
1,000,000,000,000,000
10,000,000,000,000,00
100,000,000,000,000,0
1,00,00,00,00,00,00,000
```

#### DecimalSeparator member.

```PHP
public $DecimalSeparator = '.';
```

The DecimalSeparator member tells the number formatter which character to use to separate whole numbers from fractions (e.g., the period in `1,234.56`).

Example usage:

```PHP
$Obj = new \Maikuolan\Common\NumberFormatter();

$Obj->DecimalSeparator = "⎖";
echo $Obj->format('1234567.89', 2) . PHP_EOL;

$Obj->DecimalSeparator = "—";
echo $Obj->format('1234567.89', 2) . PHP_EOL;

$Obj->GroupSeparator = '.';
$Obj->DecimalSeparator = ',';
echo $Obj->format('1234567.89', 2) . PHP_EOL;
```

Output:

```
1,234,567⎖89
1,234,567—89
1.234.567,89
```

#### Base member.

```PHP
public $Base = 10;
```

The Base member tells the number formatter which base to use to express numbers. This will typically be 10, but sometimes other bases may be needed. The mechanism for switching between bases relies upon PHP's internal `base_convert()` function, which requires that bases be between 2 and 36 inclusive. The Base member must therefore be set to a value between 2 and 36 inclusive (otherwise it won't work properly).

An example that uses `1e+9` (`1,000,000,000`):

```PHP
$Obj = new \Maikuolan\Common\NumberFormatter();

for ($Obj->Base = 2; $Obj->Base < 37; $Obj->Base++) {
    echo 'Base ' . $Obj->Base . ': ' . $Obj->format(1e+9) . PHP_EOL;
}
```

Output:

```
Base 2: 111,011,100,110,101,100,101,000,000,000
Base 3: 2,120,200,200,021,010,001
Base 4: 323,212,230,220,000
Base 5: 4,022,000,000,000
Base 6: 243,121,245,344
Base 7: 33,531,600,616
Base 8: 7,346,545,000
Base 9: 2,520,607,101
Base 10: 1,000,000,000
Base 11: 473,523,88a
Base 12: 23a,a93,854
Base 13: 12c,23a,19c
Base 14: 96,b4b,6b6
Base 15: 5c,bd1,46a
Base 16: 3b,9ac,a00
Base 17: 27,750,aa7
Base 18: 1b,73h,dda
Base 19: 12,4g6,g1i
Base 20: f,ca0,000
Base 21: b,dhi,eed
Base 22: 8,i0i,7fa
Base 23: 6,h8a,c3k
Base 24: 5,5e1,n2g
Base 25: 4,2a0,000
Base 26: 3,647,joc
Base 27: 2,fii,731
Base 28: 2,22p,q5k
Base 29: 1,jlp,2ii
Base 30: 1,b4h,13a
Base 31: 1,3sp,5mg
Base 32: tpl,ig0
Base 33: pi7,fla
Base 34: m0a,nuo
Base 35: j1d,lik
Base 36: gjd,gxs
```

Now, as an example to demonstrate working with fractions:

```PHP
$Obj = new \Maikuolan\Common\NumberFormatter();

for ($Obj->Base = 2; $Obj->Base < 37; $Obj->Base++) {
    echo 'Base ' . $Obj->Base . ': ' . $Obj->format('10.5', 4) . ' ~ ' . $Obj->format('256.25', 4) . PHP_EOL;
}
```

Output:

```
Base 2: 1,010.1000 ~ 100,000,000.0100
Base 3: 101.1111 ~ 100,111.0202
Base 4: 22.2000 ~ 10,000.1000
Base 5: 20.2222 ~ 2,011.1111
Base 6: 14.3000 ~ 1,104.1300
Base 7: 13.3333 ~ 514.1515
Base 8: 12.4000 ~ 400.2000
Base 9: 11.4444 ~ 314.2222
Base 10: 10.5000 ~ 256.2500
Base 11: a.5555 ~ 213.2828
Base 12: a.6000 ~ 194.3000
Base 13: a.6666 ~ 169.3333
Base 14: a.7000 ~ 144.3700
Base 15: a.7777 ~ 121.3b3b
Base 16: a.8000 ~ 100.4000
Base 17: a.8888 ~ f1.4444
Base 18: a.9000 ~ e4.4900
Base 19: a.9999 ~ d9.4e4e
Base 20: a.a000 ~ cg.5000
Base 21: a.aaaa ~ c4.5555
Base 22: a.b000 ~ be.5b00
Base 23: a.bbbb ~ b3.5h5h
Base 24: a.c000 ~ ag.6000
Base 25: a.cccc ~ a6.6666
Base 26: a.d000 ~ 9m.6d00
Base 27: a.dddd ~ 9d.6k6k
Base 28: a.e000 ~ 94.7000
Base 29: a.eeee ~ 8o.7777
Base 30: a.f000 ~ 8g.7f00
Base 31: a.ffff ~ 88.7n7n
Base 32: a.g000 ~ 80.8000
Base 33: a.gggg ~ 7p.8888
Base 34: a.h000 ~ 7i.8h00
Base 35: a.hhhh ~ 7b.8q8q
Base 36: a.i000 ~ 74.9000
```

**Important:** Please be aware that switching bases may result in a loss of precision (meaning that the resulting formatted numbers may sometimes be subject to some degree of inaccuracy).

---


Last Updated: 7 July 2022 (2022.07.07).
