Skip to content

ext/intl: Add DECIMAL_COMPACT_SHORT and DECIMAL_COMPACT_LONG for NumberFormatter #17975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ext/intl/formatter/formatter.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class NumberFormatter
public const int PATTERN_DECIMAL = UNKNOWN;
/** @cvalue UNUM_DECIMAL */
public const int DECIMAL = UNKNOWN;
/** @cvalue UNUM_DECIMAL_COMPACT_SHORT */
public const int DECIMAL_COMPACT_SHORT = UNKNOWN;
/** @cvalue UNUM_DECIMAL_COMPACT_LONG */
public const int DECIMAL_COMPACT_LONG = UNKNOWN;
/** @cvalue UNUM_CURRENCY */
public const int CURRENCY = UNKNOWN;
/** @cvalue UNUM_PERCENT */
Expand Down
14 changes: 13 additions & 1 deletion ext/intl/formatter/formatter_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 57 additions & 0 deletions ext/intl/tests/formatter_format_decimal_compact.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
--TEST--
numfmt_format_currency() icu >= 4.8
--EXTENSIONS--
intl
--FILE--
<?php

function ut_main()
{
$locales = array(
'en_UK',
'en_US',
'ru',
'zh_CN',
'ro',
'uk',
'en',
'bg'
);

$number = 1234567.89;

$res_str = '';
foreach( $locales as $locale )
{
$fmt = ut_nfmt_create( $locale, NumberFormatter::DECIMAL_COMPACT_SHORT );
$res_str .= "$locale: short = " . ut_nfmt_format ($fmt, $number) . "\n";

$fmt = ut_nfmt_create( $locale, NumberFormatter::DECIMAL_COMPACT_LONG );
$res_str .= "$locale: long = " . ut_nfmt_format ($fmt, $number) . "\n";
}
return $res_str;
}

include_once( 'ut_common.inc' );

// Run the test
ut_run();

?>
--EXPECTF--
en_UK: short = 1.2M
en_UK: long = 1.2 million
en_US: short = 1.2M
en_US: long = 1.2 million
ru: short = 1,2 млн
ru: long = 1,2 миллиона
zh_CN: short = 123万
zh_CN: long = 123万
ro: short = 1,2 mil.
ro: long = 1,2 milioane
uk: short = 1,2 млн
uk: long = 1,2 мільйона
en: short = 1.2M
en: long = 1.2 million
bg: short = 1,2 млн.
bg: long = 1,2 милиона
Loading