{"action":"created","issue":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/12520","repository_url":"https://api.github.com/repos/yiisoft/yii2","labels_url":"https://api.github.com/repos/yiisoft/yii2/issues/12520/labels{/name}","comments_url":"https://api.github.com/repos/yiisoft/yii2/issues/12520/comments","events_url":"https://api.github.com/repos/yiisoft/yii2/issues/12520/events","html_url":"https://github.com/yiisoft/yii2/issues/12520","id":176418133,"number":12520,"title":"Formatter::asDecimal() with intl when $decimals not set","user":{"login":"PowerGamer1","id":8275897,"avatar_url":"https://avatars.githubusercontent.com/u/8275897?v=3","gravatar_id":"","url":"https://api.github.com/users/PowerGamer1","html_url":"https://github.com/PowerGamer1","followers_url":"https://api.github.com/users/PowerGamer1/followers","following_url":"https://api.github.com/users/PowerGamer1/following{/other_user}","gists_url":"https://api.github.com/users/PowerGamer1/gists{/gist_id}","starred_url":"https://api.github.com/users/PowerGamer1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PowerGamer1/subscriptions","organizations_url":"https://api.github.com/users/PowerGamer1/orgs","repos_url":"https://api.github.com/users/PowerGamer1/repos","events_url":"https://api.github.com/users/PowerGamer1/events{/privacy}","received_events_url":"https://api.github.com/users/PowerGamer1/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/yiisoft/yii2/labels/status:need%20more%20info","name":"status:need more info","color":"d4c5f9"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-09-12T16:15:18Z","updated_at":"2016-09-15T11:41:24Z","closed_at":null,"body":"```PHP\r\n/**\r\n * Formats the value as a decimal number.\r\n * ...\r\n * @param integer $decimals the number of digits after the decimal point. If not given the number of digits is determined from the\r\n * [[locale]] and if the [PHP intl extension](http://php.net/manual/en/book.intl.php) is not available defaults to `2`.\r\n * ...\r\n */\r\npublic function asDecimal($value, $decimals = null, $options = [], $textOptions = [])\r\n```\r\nWhen PHP intl extension is enabled the number of decimal digits after the decimal point is NOT determined automatically from locale because ICU does not have such functionality. If intl is enabled and `$decimals` is `null` the `Formatter::createNumberFormatter()` will do:\r\n```PHP\r\n        if ($decimals !== null) {\r\n            $formatter->setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, $decimals);\r\n            $formatter->setAttribute(NumberFormatter::MIN_FRACTION_DIGITS, $decimals);\r\n        }\r\n```\r\nIf not specified `NumberFormatter::MIN_FRACTION_DIGITS` defaults to 0 and `NumberFormatter::MIN_FRACTION_DIGITS` defaults to 3 ALWAYS regardless of locale set for the `NumberFormatter`.\r\n\r\nThis is very easy to test:\r\n```PHP\r\n<?php\r\n$f = new \\NumberFormatter(\"en\", \\NumberFormatter::DECIMAL); // set whatever locale you want\r\nvar_dump($f->getLocale());\r\nvar_dump($f->getAttribute(NumberFormatter::MIN_FRACTION_DIGITS)); // will be 0\r\nvar_dump($f->getAttribute(NumberFormatter::MAX_FRACTION_DIGITS)); // will be 3\r\n```\r\n`Formatter::asDecimal()` should be fixed to always default to a value of 2 for `$decimals` regardless if intl is enabled or not."},"comment":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/comments/247305524","html_url":"https://github.com/yiisoft/yii2/issues/12520#issuecomment-247305524","issue_url":"https://api.github.com/repos/yiisoft/yii2/issues/12520","id":247305524,"user":{"login":"PowerGamer1","id":8275897,"avatar_url":"https://avatars.githubusercontent.com/u/8275897?v=3","gravatar_id":"","url":"https://api.github.com/users/PowerGamer1","html_url":"https://github.com/PowerGamer1","followers_url":"https://api.github.com/users/PowerGamer1/followers","following_url":"https://api.github.com/users/PowerGamer1/following{/other_user}","gists_url":"https://api.github.com/users/PowerGamer1/gists{/gist_id}","starred_url":"https://api.github.com/users/PowerGamer1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PowerGamer1/subscriptions","organizations_url":"https://api.github.com/users/PowerGamer1/orgs","repos_url":"https://api.github.com/users/PowerGamer1/repos","events_url":"https://api.github.com/users/PowerGamer1/events{/privacy}","received_events_url":"https://api.github.com/users/PowerGamer1/received_events","type":"User","site_admin":false},"created_at":"2016-09-15T11:41:24Z","updated_at":"2016-09-15T11:41:24Z","body":"> why exactly?\r\n\r\nBecause currently if someone uses `Formatter` without intl and then enables intl many numbers in different places will be formatted differently. The result of decimal number formatting with and without intl ideally should be the same. For example, when someone uses `asDecimal` to format currency numbers (without currency code, so `asCurrency` cannot be used) without intl they will be formatted correctly: 123.4 will be 123.40. But then if intl is enabled the currency number 123.4 will be formatted incorrectly as 123.4.\r\n\r\nBesides, at the very least incorrect comment:\r\n```PHP\r\nIf not given the number of digits is determined from the [[locale]]\r\n```\r\nshould be fixed.\r\n"}}
{"actor":{"display_login":"PowerGamer1"}}