如何修复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,因为我也想读“美分”。