PluginProbe
TablePress – Tables in WordPress made easy / 3.4
TablePress – Tables in WordPress made easy v3.4
3.4 3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.12 1.14 1.9.2 2.0.4 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3 2.3.1 2.3.2 2.4 2.4.1 2.4.2 2.4.3 All 45 releases
tablepress / libraries / vendor / PhpSpreadsheet / Style / NumberFormat / Wizard / Number.php

Number.php in TablePress – Tables in WordPress made easy 3.4, at libraries/vendor/PhpSpreadsheet/Style/NumberFormat/Wizard/Number.php

58 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace TablePress\PhpOffice\PhpSpreadsheet\Style\NumberFormat\Wizard;
4
5 use TablePress\PhpOffice\PhpSpreadsheet\Exception;
6
7 class Number extends NumberBase implements Wizard
8 {
9 public const WITH_THOUSANDS_SEPARATOR = true;
10
11 public const WITHOUT_THOUSANDS_SEPARATOR = false;
12
13 protected bool $thousandsSeparator = true;
14
15 /**
16 * @param int $decimals number of decimal places to display, in the range 0-30
17 * @param bool $thousandsSeparator indicator whether the thousands separator should be used, or not
18 * @param ?string $locale Set the locale for the number format; or leave as the default null.
19 * Locale has no effect for Number Format values, and is retained here only for compatibility
20 * with the other Wizards.
21 * If provided, Locale values must be a valid formatted locale string (e.g. 'en-GB', 'fr', uz-Arab-AF).
22 *
23 * @throws Exception If a provided locale code is not a valid format
24 */
25 public function __construct(
26 int $decimals = 2,
27 bool $thousandsSeparator = self::WITH_THOUSANDS_SEPARATOR,
28 ?string $locale = null
29 ) {
30 $this->setDecimals($decimals);
31 $this->setThousandsSeparator($thousandsSeparator);
32 $this->setLocale($locale);
33 }
34
35 public function setThousandsSeparator(bool $thousandsSeparator = self::WITH_THOUSANDS_SEPARATOR): void
36 {
37 $this->thousandsSeparator = $thousandsSeparator;
38 }
39
40 /**
41 * As MS Excel cannot easily handle Lakh, which is the only locale-specific Number format variant,
42 * we don't use locale with Numbers.
43 */
44 protected function getLocaleFormat(): string
45 {
46 return $this->format();
47 }
48
49 public function format(): string
50 {
51 return sprintf(
52 '%s0%s',
53 $this->thousandsSeparator ? '#,##' : null,
54 $this->decimals > 0 ? '.' . str_repeat('0', $this->decimals) : null
55 );
56 }
57 }
58