xref: /PHP-8.3/ext/intl/tests/formatter_parse.phpt (revision 74859783)
1--TEST--
2numfmt_parse()
3--EXTENSIONS--
4intl
5--FILE--
6<?php
7
8/*
9 * Number parsing.
10 */
11
12
13function ut_main()
14{
15    $res_str = '';
16
17    // Test parsing float number.
18    $fmt = ut_nfmt_create( "en_US", NumberFormatter::DECIMAL );
19    $res_str .= ut_nfmt_parse( $fmt, "123E-3" ) . "\n";
20
21    // Test parsing float number as integer.
22    $fmt = ut_nfmt_create( "en_US", NumberFormatter::DECIMAL );
23    $res_str .= ut_nfmt_parse( $fmt, "1.23", NumberFormatter::TYPE_INT32 ) . "\n";
24
25    // Test specifying non-zero parsing start position.
26    $fmt = ut_nfmt_create( "en_US", NumberFormatter::DECIMAL );
27    $pos = 2;
28    $res_str .= ut_nfmt_parse( $fmt, "0.123 here", NumberFormatter::TYPE_DOUBLE, $pos ) . "\n";
29    $res_str .= "$pos\n";
30
31    return $res_str;
32}
33
34include_once( 'ut_common.inc' );
35ut_run();
36
37?>
38--EXPECT--
390.123
401
41123
425
43