Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何修复php中的拼写_Php_Intl - Fatal编程技术网

如何修复php中的拼写

如何修复php中的拼写,php,intl,Php,Intl,大家好。我的代码有问题。 我试图制作一个简单的程序,将数字转换成文字,但我遇到了一些问题,下面是我的代码 $num = 900.00; $exp = explode('.', $num); $f = new NumberFormatter("en_US", NumberFormatter::SPELLOUT); $num_words = ucfirst($f->format($exp[0])) . ' point ' . ucfirst($f->format($e

大家好。我的代码有问题。 我试图制作一个简单的程序,将数字转换成文字,但我遇到了一些问题,下面是我的代码

$num = 900.00;
$exp = explode('.', $num);
$f = new NumberFormatter("en_US", NumberFormatter::SPELLOUT);
$num_words = ucfirst($f->format($exp[0])) . ' point ' . ucfirst($f->format($exp[1]));
我期待着一个

九百

这是我的

九百点零

这里是错误

注意:未定义的偏移量:1


有人能帮我吗。我在努力寻找答案。谢谢大家

您需要像这样使用
if else
来检查点后面的数字。如果为零或小于1,则不要使用
point
word

$num = floatval(900.00);
$exp = explode('.', $num);
$f = new NumberFormatter("en_US", NumberFormatter::SPELLOUT);
// check the number if the number behind point/comma is less than 1
if(count($exp) == 1){
    $num_words = ucfirst($f->format($exp[0]));
}else{
// other than that print with point
    $num_words = ucfirst($f->format($exp[0])) . ' point ' . ucfirst($f->format($exp[1]));
}

为什么使用
$num\u words=ucfirst($f->format($exp[0])。'点'。ucfirst($f->format($exp[1])?为什么不干脆
$num_words=ucfirst($f->format($exp[0])@Gagantous,因为我也想读“美分”。