money-format

Defining cross-platform money_format function (Linux and Windows)

邮差的信 提交于 2020-01-21 04:50:43
问题 I have read that money_format is not available on windows, and on some Linux distributions (i.e. BSD 4.11 variants). But I want to write cross-platform library using normal function, when available and using this workaround when not, so my library will be able to run on every PHP-based web server. Is there any simple solution to check whether built-in function is available and if not to include the solution from above? 回答1: The function money_format() is only defined if the system has strfmon

PHP money format with spaces

孤人 提交于 2019-12-22 03:47:09
问题 I am wondering if there is a way to separate thousands with space character. For example: $number = 21234.56; setlocale(LC_ALL, 'pl_PL.utf8'); echo money_format('%i', $number); is giving me: 21.234,56 PLN And I want: 21 234,56 PLN I don't want to make str_replace. I am sure there is a better way. 回答1: You can use number-format. For example : echo number_format($number, 2, ',', ' '); But you will have to put the unit yourself. Otherwise, this comment of the money_format documentation page

yii2 - how to set currency decimal value

有些话、适合烂在心里 提交于 2019-12-21 16:17:11
问题 I want my currency to ignore decimal value, so far I have this: main.php: 'formatter' => [ 'class' => 'yii\i18n\Formatter', 'thousandSeparator' => '.', 'decimalSeparator' => ',', 'currencyCode' => '€', ], view: [ 'attribute' => 'Score', 'format' => 'currency', ], Any idea on how to move forward? 回答1: The manual on currencyCode : The 3-letter ISO 4217 currency code indicating the default currency to use Try setting currencyCode to 'EUR' (though that doesn't seem to be that important) and put

PHP money_format(); £ sign not GBP

痴心易碎 提交于 2019-12-21 07:25:11
问题 I cannot work out how to get the currency symbol? At the moment I am using setlocale(LC_MONETARY, 'en_GB'); money_format('%i', 1000); Which give me the output GBP1,000 But I want £1,000 I have checked out the PHP manual but it isn't that helpful. Any ideas? 回答1: Have you tried this? setlocale(LC_MONETARY, 'en_GB'); utf8_encode(money_format('%n', 1000)); 回答2: This worked for me: setlocale(LC_MONETARY, 'en_GB.UTF-8'); money_format('%n', 1000); It's similar to the selected solution, however it

PHP money_format

馋奶兔 提交于 2019-12-19 05:47:44
问题 I'm using on money_format with the first parameter being '%n' to include the dollar sign, and I have the locale set to en_US but it still doesn't include it. Why? 回答1: From the PHP.net comment: If money_format doesn't seem to be working properly, make sure you are defining a valid locale. For example, on Debian, 'en_US' is not a valid locale - you need 'en_US.UTF-8' or 'en_US.ISO-8559-1'. This was frustrating me for a while. Debian has a list of valid locales at /usr/share/i18n/SUPPORTED;

Use php money format and remove the numbers after the decimal place for GBP

不想你离开。 提交于 2019-12-18 16:54:49
问题 I want to format some numbers from my analytics into currency using the GB money format but as its for a dashboard and doesn't need to be that precise so I want to remove the pence (numbers after the decimal place) and round it which helps with the css layout, how do I do this? Rounding up or down to the nearest pound would be fine. My code is as follows: //set locale for currency setlocale(LC_MONETARY, 'en_GB'); $sales = '8932.83'; echo utf8_encode(money_format('%n', $sales)); This outputs:

Alternative to money_format() Function in PHP on Windows Platform

送分小仙女□ 提交于 2019-12-17 10:47:40
问题 I am using the money_format() function in PHP, which gives the following error: Fatal error: Call to undefined function money_format() Searches about this error reveal that the function money_format() is only defined if the system has strfmon capabilities. For example, Windows does not, so money_format() is undefined in Windows. Is there an equivalent PHP function available for Windows? 回答1: If you have the Intl extension, you can use NumberFormatter::formatCurrency — Format a currency value

String.Format Same Code Different View

為{幸葍}努か 提交于 2019-12-13 14:20:02
问题 I have a code like this; GridView1.FooterRow.Cells[11].Text = String.Format("{0:c}", sumKV) In my computer this code gives a result like that; But when I upload this code to my virtual machine it looks like this; TL means Turkish Liras. But I don't want to show the currency. I just want numbers. I also don't want to change the formating of numbers. (Like 257.579,02) How can I only delete TL in this code? 回答1: I would use this: var cultureWithoutCurrencySymbol = (CultureInfo)CultureInfo