formatter_format4.phpt 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. --TEST--
  2. numfmt_format() icu >= 53.1 && icu < 54.1
  3. --SKIPIF--
  4. <?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
  5. <?php if (version_compare(INTL_ICU_VERSION, '53.1') < 0) die('skip for ICU >= 53.1'); ?>
  6. <?php if (version_compare(INTL_ICU_VERSION, '54.1') >= 0) die('skip for ICU < 54.1'); ?>
  7. --FILE--
  8. <?php
  9. /*
  10. * Format a number using misc locales/patterns.
  11. */
  12. /*
  13. * TODO: doesn't pass on ICU 3.6 because 'ru' and 'de' locales changed
  14. * currency and percent formatting.
  15. */
  16. function ut_main()
  17. {
  18. $styles = array(
  19. NumberFormatter::PATTERN_DECIMAL => '##.#####################',
  20. NumberFormatter::DECIMAL => '',
  21. NumberFormatter::CURRENCY => '',
  22. NumberFormatter::PERCENT => '',
  23. NumberFormatter::SCIENTIFIC => '',
  24. NumberFormatter::SPELLOUT => '@@@@@@@',
  25. NumberFormatter::ORDINAL => '',
  26. NumberFormatter::DURATION => '',
  27. NumberFormatter::PATTERN_RULEBASED => '#####.###',
  28. 1234999, // bad one
  29. );
  30. $integer = array(
  31. NumberFormatter::ORDINAL => '',
  32. NumberFormatter::DURATION => '',
  33. );
  34. $locales = array(
  35. 'en_US',
  36. 'ru_UA',
  37. 'de',
  38. 'fr',
  39. 'en_UK'
  40. );
  41. $str_res = '';
  42. $number = 1234567.891234567890000;
  43. foreach( $locales as $locale )
  44. {
  45. $str_res .= "\nLocale is: $locale\n";
  46. foreach( $styles as $style => $pattern )
  47. {
  48. $fmt = ut_nfmt_create( $locale, $style, $pattern );
  49. if(!$fmt) {
  50. $str_res .= "Bad formatter!\n";
  51. continue;
  52. }
  53. $str_res .= dump( isset($integer[$style])?ut_nfmt_format( $fmt, $number, NumberFormatter::TYPE_INT32):ut_nfmt_format( $fmt, $number ) ) . "\n";
  54. }
  55. }
  56. return $str_res;
  57. }
  58. include_once( 'ut_common.inc' );
  59. // Run the test
  60. ut_run();
  61. ?>
  62. --EXPECTREGEX--
  63. Locale is: en_US
  64. '1234567.89123457'
  65. '1,234,567.891'
  66. '\$1,234,567.89'
  67. '123,456,789%'
  68. '1.23456789123457E6'
  69. 'one million,? two hundred (and )?thirty-four thousand,? five hundred (and )?sixty-seven point eight nine one two three four five seven'
  70. '1,234,567(th|ᵗʰ)'
  71. '342:56:07'
  72. '#####.###'
  73. 'USD1,234,567.89'
  74. Locale is: ru_UA
  75. '1234567,89123457'
  76. '1 234 567,891'
  77. '1 234 567,89 ?(грн\.|₴)'
  78. '123 456 789 ?%'
  79. '1,23456789123457E6'
  80. 'один миллион двести тридцать четыре тысяч пятьсот шестьдесят семь запятая восемь девять один два три четыре пять семь'
  81. '1 234 567.?'
  82. '1 234 567'
  83. '#####.###'
  84. '1 234 567,89 UAH'
  85. Locale is: de
  86. '1234567,89123457'
  87. '1.234.567,891'
  88. '(¤ )?1.234.567,89( ¤)?'
  89. '123\.456\.789 %'
  90. '1,23456789123457E6'
  91. 'eine Million zwei­hundert­vier­und­dreißig­tausend­fünf­hundert­sieben­und­sechzig Komma acht neun eins zwei drei vier fünf sieben'
  92. '1.234.567.?'
  93. '1.234.567'
  94. '#####.###'
  95. '1.234.567,89 ¤¤'
  96. Locale is: fr
  97. '1234567,89123457'
  98. '1 234 567,891'
  99. '1 234 567,89 ¤'
  100. '123 456 789 ?%'
  101. '1,23456789123457E6'
  102. 'un million deux cent trente-quatre mille cinq cent soixante-sept virgule huit neuf un deux trois quatre cinq sept'
  103. '1 234 567e'
  104. '1 234 567'
  105. '#####.###'
  106. '1 234 567,89 ¤¤'
  107. Locale is: en_UK
  108. '1234567.89123457'
  109. '1,234,567.891'
  110. '¤1,234,567.89'
  111. '123,456,789%'
  112. '1.23456789123457E6'
  113. 'one million,? two hundred (and )?thirty-four thousand,? five hundred (and )?sixty-seven point eight nine one two three four five seven'
  114. '1,234,567(th|ᵗʰ)'
  115. '342:56:07'
  116. '#####.###'
  117. '¤¤1,234,567.89'