我很难解决我的数字到php中的单词功能。
<?php
$num = 29.29;
$f = new NumberFormatter("en", NumberFormatter::SPELLOUT);
echo $f->format($num);
//outputs Twenty-nine and two nine
?>Run Code Online (Sandbox Code Playgroud)
如何将其格式化为:29和29?
请帮忙!
首先,29.29应该如何发音是Twenty nine point two nine。话虽如此,如果您需要精确地获取Twenty-nine and Twenty-nine,则可以使用以下代码:
<?php
$num = 29.29;
$exp = explode('.', $num);
$f = new NumberFormatter("en_US", NumberFormatter::SPELLOUT);
echo ucfirst($f->format($exp[0])) . ' and ' . ucfirst($f->format($exp[1]));
//outputs Twenty-nine and Twenty-nine
?>
Run Code Online (Sandbox Code Playgroud)