PHP.mk документација

NumberFormatter::parseCurrency

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

numberformatter.parsecurrency.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека numberformatter.parsecurrency.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
NumberFormatter::parseCurrency

Референца за `numberformatter.parsecurrency.php` со подобрена типографија и навигација.

numberformatter.parsecurrency.php

NumberFormatter::parseCurrency

numfmt_parse_currency

Класата Collator

NumberFormatter::parseCurrency -- numfmt_parse_currencyParse a currency number

= NULL

Напиши целосна ознака на елемент

public NumberFormatter::parseCurrency(string $string, string &$currency, int &$offset = null): float|false

Процедурален стил

numfmt_parse_currency(
         NumberFormatter $formatter,
         string $string,
         string &$currency,
         int &$offset = null
): float|false

Parse a string into a float and a currency using the current formatter.

Параметри

formatter

NumberFormatter object.

currency

Parameter to receive the currency name (3-letter ISO 4217 currency code).

offset

Позиција во стрингот од каде да се започне со парсирање. При враќање, оваа вредност ќе ја задржи позицијата каде заврши парсирањето.

Вратени вредности

The parsed numeric value or false при грешка.

Примери

Пример #1 numfmt_parse_currency() example

<?php
$fmt
= numfmt_create( 'de_DE', NumberFormatter::CURRENCY );
$num = "1.234.567,89\xc2\xa0$";
echo
"We have ".numfmt_parse_currency($fmt, $num, $curr)." in $curr\n";
?>

Пример #2 OO пример

<?php
$fmt
= new NumberFormatter( 'de_DE', NumberFormatter::CURRENCY );
$num = "1.234.567,89\xc2\xa0$";
echo
"We have ".$fmt->parseCurrency($num, $curr)." in $curr\n";
?>

Пример #1 Пример што покажува затворачка ознака што го опфаќа последниот нов ред

We have 1234567.89 in USD

Види Исто така

Белешки од корисници 1 белешка

info at mm-newmedia dot de
пред 8 години
In reply to daniel at danielphenry dot com example note beneath. The given example by Daniel returns false under PHP7.x, which is a normal behavior since NumberFormatter::parseCurrency() is a method for parsing currency strings. It is trying to split up the given string in a float and a currency. 

While using strict types under PHP7 the following example makes it more clearer.

<?php
declare(strict_types=1);
namespace MMNewmedia;

$oParser = new \NumberFormatter('de_DE', \NumberFormatter::CURRENCY);
var_dump($oParser->parseCurrency("1.234.567,89\xc2\xa0€", $currency), $currency));
?>

This example returns: "float(1234567.89) string(3) "EUR"

This is the expected behavior.

The following example runs into a type error, which is absolutely right, since this method is vor parsing strings and not vor formatting floats into currency strings.

<?php
declare(strict_types=1);
namespace MMNewmedia;

try {
    $oCurrencyParser = new \NumberFormatter('de_DE', \NumberFormatter::CURRENCY);
    $currency = 'EUR';
    var_dump($oCurrencyParser->parseCurrency(1.234, $currency), $currency);
} catch (\TypeError $oTypeError) {
    var_dump($oTypeError->getMessage());
}
?>

This example returns "NumberFormatter::parseCurrency() expects parameter 1 to be string, float given".

If you want to parse floats into a currency string use the http://php.net/manual/en/numberformatter.formatcurrency.php method as shown in the next example.

<?php
declare(strict_types=1);
namespace MMNewmedia;

$oFormatter = new \NumberFormatter('de_DE', \NumberFormatter::CURRENCY);
var_dump($oFormatter->formatCurrency(1234567.89, 'EUR'));
?>

This returns string(17) "1.234.567,89 €" as expected.
На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.