转换数字 |整数到单词
Convert number | integer to words
我想将整数转换为单词,例如:29 将变为 二十九,而 50 将变为 五十。如何使用 PHP?
实现此目的
这是我目前所拥有的,但没有提供所需的输出。
$fees_so = $form_data_fees['field']['4'];
$feesInWords = strval($fees_so);
echo $feesInWords;
您可以使用 NumberFormatter class 和 SPELLOUT
:
$nf = new NumberFormatter("en", NumberFormatter::SPELLOUT);
echo $nf->format(1999); // one thousand nine hundred ninety-nine
假设你有一个数组:
$list_of_fees = array("£29", "£50", "£64");;
for($i = 0; $i < 3; $i++)
echo substr($list_of_fees[$i], 1) . " Pounds";
我最终使用来自@aniket-sahrawat 的代码稍加调整就找到了解决方案
这是代码,以防将来有人需要它...
<?php
$fees_so = $form_data_fees['field']['4'];
$words = filter_var($fees_so, FILTER_SANITIZE_NUMBER_INT);
$nf = new NumberFormatter("en", NumberFormatter::SPELLOUT);
echo $nf->format($words);
?>
我想将整数转换为单词,例如:29 将变为 二十九,而 50 将变为 五十。如何使用 PHP?
实现此目的这是我目前所拥有的,但没有提供所需的输出。
$fees_so = $form_data_fees['field']['4'];
$feesInWords = strval($fees_so);
echo $feesInWords;
您可以使用 NumberFormatter class 和 SPELLOUT
:
$nf = new NumberFormatter("en", NumberFormatter::SPELLOUT);
echo $nf->format(1999); // one thousand nine hundred ninety-nine
假设你有一个数组:
$list_of_fees = array("£29", "£50", "£64");;
for($i = 0; $i < 3; $i++)
echo substr($list_of_fees[$i], 1) . " Pounds";
我最终使用来自@aniket-sahrawat 的代码稍加调整就找到了解决方案
这是代码,以防将来有人需要它...
<?php
$fees_so = $form_data_fees['field']['4'];
$words = filter_var($fees_so, FILTER_SANITIZE_NUMBER_INT);
$nf = new NumberFormatter("en", NumberFormatter::SPELLOUT);
echo $nf->format($words);
?>