data-values / number
Numerical value objects, parsers and formatters
Installs: 294 903
Dependents: 16
Suggesters: 2
Security: 0
Stars: 18
Watchers: 18
Forks: 6
Open Issues: 4
pkg:composer/data-values/number
Requires
- php: >=7.4
- data-values/common: ~1.0|~0.4.0|~0.3.0
- data-values/data-values: ~3.0|~2.0|~1.0|~0.1
- data-values/interfaces: ~1.0|~0.2.0
Requires (Dev)
- ext-bcmath: *
- mediawiki/mediawiki-codesniffer: 45.0.0
- phpunit/phpunit: ~8.5
- dev-master
- 0.13.0
- 0.12.3
- 0.12.2
- 0.12.1
- 0.12.0
- 0.11.1
- 0.11.0
- 0.10.2
- 0.10.1
- 0.10.0
- 0.9.1
- 0.9.0
- 0.8.3
- 0.8.2
- 0.8.1
- 0.8.0
- 0.7.0
- 0.6.0
- 0.5
- 0.4.1
- 0.4
- 0.3
- 0.2
- 0.1
- dev-feat/upgrade-mediawiki-codesniffer-20241206
- dev-updateCodeStyle
- dev-comment
- dev-lineLength120
- dev-release083
- dev-one082Release
- dev-optional-bounds
This package is auto-updated.
Last update: 2025-10-10 15:37:26 UTC
README
Library containing value objects to represent numeric information, parsers to turn user input into such value objects, and formatters to turn them back into user consumable representations.
It is part of the DataValues set of libraries.
On Packagist:
Installation
The recommended way to use this library is via Composer.
Composer
To add this package as a local, per-project dependency to your project, simply add a
dependency on data-values/number to your project's composer.json file.
Here is a minimal example of a composer.json file that just defines a dependency on
version 0.8 of this package:
{
"require": {
"data-values/number": "0.12.*"
}
}
Manual
Get the code of this package, either via git, or some other means. Also get all dependencies. You can find a list of the dependencies in the "require" section of the composer.json file. Then take care of autoloading the classes defined in the src directory.
Tests
This library comes with a set up PHPUnit tests that cover all non-trivial code. You can run these tests using the PHPUnit configuration file found in the root directory. The tests can also be run via TravisCI, as a TravisCI configuration file is also provided in the root directory.
Authors
DataValues Number was created by Wikimedia Deutschland employees for the Wikidata project.
Release notes
0.13.0 (2024-12-10)
- Drop support for PHP 7.2, 7.3
- Upgrade codesniffer rules to current
mediawiki/mediawiki-codesnifferversion (45.0.0) - Make nullable type parameter declarations explicit for compatibility with PHP 8.4
0.12.3 (2022-10-24)
- Allow use with data-values/common 1.1.0 and data-values/interfaces 1.x
0.12.2 (2022-10-21)
- Fix
QuantityValueandUnboundedQuantityValuehashes to be identical to version 0.11.1.
0.12.1 (2022-10-21)
- Allow use with data-values/data-values 3.1.0
0.12.0 (2022-10-21)
- Improve compatibility with PHP 8.1;
in particular, the new
__serialize/__unserializemethods are implemented now (in addition to the still supportedSerializableinterface). Make sure to also usedata-values/data-valuesversion 3.1.0 (or later) to keep hashes stable. - Remove the
DATAVALUES_NUMBER_VERSIONconstant.
0.11.1 (2021-03-31)
- Fix
DecimalMath::productWithoutBCfor products larger than 2^63-1 (the maximum value of a signed 64 bit integer).
0.11.0 (2021-03-15)
- Drop support for php versions older than 7.2 and HHVM
0.10.2 (2021-03-15)
- Allow use with data-values/common 1.0.0
- Allow use with data-values/interfaces 1.0.0
- Allow use with data-values/data-values 3.0.0
0.10.1 (2018-10-31)
- Allow installation together with DataValues 2.x
- DecimalMath products now get rounded to 127 characters to avoid a fatal error
0.10.0 (2018-04-11)
- Changed the float to string conversion algorithm for
DecimalValue,QuantityValue, andUnboundedQuantityValue. Instead of a hundred mostly irrelevant decimal places it now uses PHP's "serialize_precision" default of 17 significant digits. - Drop compatibility with data-values/interfaces 0.1 and data-values/common 0.2
0.9.1 (2017-08-09)
- Allow use with data-values/common 0.4
0.9.0 (2017-08-09)
- Remove MediaWiki integration
- Strip all whitespace in DecimalParser
- Use Wikibase's CodeSniffer instead of MediaWiki's
0.8.3 (2017-06-26)
- Fixed
UnboundedQuantityValue::newFromArraynot accepting mixed values. - Deprecated
DecimalValue::newFromArrayandUnboundedQuantityValue::newFromArray. - Updated minimal required PHP version from 5.3 to 5.5.9.
0.8.2 (2016-11-17)
- Fixed
QuantityFormattersuppressing ±0 forQuantityValues. - Fixed HTML escaping in
QuantityHtmlFormatter.
0.8.1 (2016-08-02)
UnboundedQuantityValue::newFromArrayandQuantityValue::newFromArrayboth accept serializations without and with an uncertainty interval.
0.8.0 (2016-08-01)
- Added
DecimalValue::getTrimmed. - Added
UnboundedQuantityValue.QuantityValueextendsUnboundedQuantityValue.QuantityParserreturnsUnboundedQuantityValues instead of always guessing an uncertainty interval.QuantityFormatteralso acceptsUnboundedQuantityValues.
QuantityParserdefaults to ±0.5 instead of ±1 when asked to guess an uncertainty interval, e.g.1~becomes1±0.5.QuantityFormatterdoes not round any more when the value is rendered with a known uncertainty interval.- Fixed rounding algorithm in
DecimalMath(rounded 1.45 to 2 instead of 1). DecimalValueconstructor optionally accepts strings with no leading plus sign.- Removed
QuantityValue::getSignificantFigures. - Removed
QuantityValue::newFromDecimal(deprecated since 0.1). - The
$vocabularyUriFormatterparameter in theQuantityFormatterconstructor is not nullable any more.
0.7.0 (2016-04-25)
Breaking changes
- Removed deprecated
QuantityUnitFormatterinterface. - Removed deprecated
BasicQuantityUnitFormatter.
Other changes
- Fixed
DecimalValueandQuantityValueallowing values with a newline at the end. DecimalValuestrings are trimmed now, allowing any number of leading and trailing whitespace.- Added explicit compatibility with data-values/common 0.2 and 0.3.
0.6.0 (2015-09-09)
Breaking changes
QuantityFormatterconstructor parameters changed in an incompatible way.BasicNumberUnlocalizer::getUnitRegexreturns an empty string. AQuantityParserusing this does not accept units as part of the input any more.
Additions
- Added
QuantityHtmlFormatter. QuantityFormattersupports an optional format string to concatenate number and unit.
Other changes
- Deprecated
QuantityUnitFormatterinterface. - Deprecated
BasicQuantityUnitFormatter. QuantityParsernow always trims the unit it gets via option.- The component can now be installed together with DataValues Interfaces 0.2.x.
0.5.0 (2015-06-11)
Breaking changes
QuantityFormatterconstructor parameters changed in an incompatible way
Additions
- Added
QuantityUnitFormatterinterface - Added
BasicQuantityUnitFormatter - Added
QuantityFormatter::OPT_APPLY_UNIToption - Added
QuantityParser::OPT_UNIToption - Added
DecimalParser::applyDecimalExponent - Added
DecimalParser::splitDecimalExponent
Other changes
QuantityParsernow correctly detects precision for scientific notation- Made constructor parameters optional in
DecimalFormatterandQuantityFormatter - Updated DataValues Interfaces dependency to 0.1.5
0.4.1 (2014-10-09)
- The component can now be installed together with DataValues 1.x
0.4 (2014-04-24)
- Unlocalizer interface renamed to NumberUnlocalizer
- Localizer interface renamed to NumberLocalizer
- BasicUnlocalizer interface renamed to BasicNumberUnlocalizer
- BasicLocalizer interface renamed to BasicNumberLocalizer
- Introduced FORMAT_NAME class constants on ValueParsers in order to use them as expectedFormat
- Changed ValueParsers to pass rawValue and expectedFormat when constructing a ParseException
0.3 (2014-03-12)
- Unlocalizer: added getNumberRegex() and getUnitRegex()
- Unlocalizer: replaced unlocalize() with unlocalizeNumber()
- Localizer: replaced localize() with localizeNumber()
- Localizer and Unlocalizer: no longer require the target language and options in method calls
- QuantityParser: fixed parsing of internationalized quantity strings
0.2 (2013-12-16)
Removals
- IntParser got moved to data-values/common
- FloatParser got moved to data-values/common
Additions
- DecimalMath::min
- DecimalMath::max
- DecimalMath::shift
- Added option to force displaying the sign in DecimalFormatter
Improvements
- QuantityParser and DecimalParser now support scientific notation
- DecimalParser now supports localized parsing of values
- DecimalFormatter now supports localization of values
Bug fixes
- Floating point errors that occurred when manipulating decimal values have been fixed. (bug 56682)
0.1 (2013-11-17)
Initial release with these features:
- DecimalMath
- DecimalValue
- QuantityValue
- DecimalFormatter
- QuantityFormatter
- DecimalParser
- FloatParser
- IntParser
- QuantityParser