formatter_format6.phpt 3.4 KB

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