aboutsummaryrefslogtreecommitdiffstats
path: root/library/intl/src/Formatter/NumberFormatterInterface.php
blob: 7211075554bd27f7231b20774b0b385db845e42f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php

namespace CommerceGuys\Intl\Formatter;

use CommerceGuys\Intl\Currency\CurrencyInterface;
use CommerceGuys\Intl\NumberFormat\NumberFormatInterface;

interface NumberFormatterInterface
{
    /* Format style constants */
    const DECIMAL = 1;
    const PERCENT = 2;
    const CURRENCY = 3;
    const CURRENCY_ACCOUNTING = 4;

    /* Currency display style constants */
    const CURRENCY_DISPLAY_SYMBOL = 1;
    const CURRENCY_DISPLAY_CODE = 2;

    /**
     * Formats a number.
     *
     * Please note that the provided value should already be rounded.
     * This formatter doesn't do any rounding of its own, and will simply
     * truncate extra digits.
     *
     * @param string $value The value to format.
     *
     * @return string
     */
    public function format($value);

    /**
     * Formats a currency value.
     *
     * Please note that the provided value should already be rounded.
     * This formatter doesn't do any rounding of its own, and will simply
     * truncate extra digits.
     *
     * @param string            $value    The value to format.
     * @param CurrencyInterface $currency The currency.
     *
     * @return string
     */
    public function formatCurrency($value, CurrencyInterface $currency);

    /**
     * Parses a formatted currency value.
     *
     * Commonly used in price input widgets where the end-user might
     * input a value using digits and symbols common to their locale.
     *
     * @param string            $value    The value to parse.
     * @param CurrencyInterface $currency The currency.
     *
     * @return string|false The parsed numeric value or FALSE on error.
     */
    public function parseCurrency($value, CurrencyInterface $currency);

    /**
     * Gets the number format.
     *
     * @return NumberFormatInterface
     */
    public function getNumberFormat();

    /**
     * Gets the minimum number of fraction digits.
     *
     * Defaults to 0 for decimal and percentage styles.
     * Defaults to null for currency styles, since the currency number of
     * fraction digits is used as the default in that case.
     *
     * @return int
     */
    public function getMinimumFractionDigits();

    /**
     * Sets the minimum number of fraction digits.
     *
     * @param int $minimumFractionDigits
     */
    public function setMinimumFractionDigits($minimumFractionDigits);

    /**
     * Gets the maximum number of fraction digits.
     *
     * Defaults to 3 for decimal and percentage styles.
     * Defaults to null for currency styles, since the currency number of
     * fraction digits is used as the default in that case.
     *
     * @return int
     */
    public function getMaximumFractionDigits();

    /**
     * Sets the maximum number of fraction digits.
     *
     * @param int $maximumFractionDigits
     */
    public function setMaximumFractionDigits($maximumFractionDigits);

    /**
     * Returns whether the major digits will be grouped.
     *
     * @return bool
     */
    public function isGroupingUsed();

    /**
     * Sets whether or not major digits should be grouped
     *
     * @param bool $groupingUsed
     */
    public function setGroupingUsed($groupingUsed);

    /**
     * Gets the currency display style.
     *
     * Controls whether a currency amount will be shown with the
     * currency symbol (CURRENCY_DISPLAY_SYMBOL) or the
     * currency code (CURRENCY_DISPLAY_CODE).
     *
     * @return int
     */
    public function getCurrencyDisplay();

    /**
     * Sets the currency display style.
     *
     * @param int $currencyDisplay One of the CURRENCY_DISPLAY_ constants.
     */
    public function setCurrencyDisplay($currencyDisplay);
}