嗨,im现在在laravel中使用php laravel,如果我想回显数字,我做了下面的代码
@php
$digit = new \NumberFormatter(Lang::locale(), \NumberFormatter::SPELLOUT);
echo $digit->format(round(10.557,3));
@endphp结果将是

但我需要的是
ten and five handred and seventy five我怎样才能改变格式。谢谢..。
发布于 2020-08-30 14:06:14
您可以尝试手动构建一个函数。
function numberToText($number) {
$digit = new \NumberFormatter(Lang::locale(), \NumberFormatter::SPELLOUT);
$numberParts = explode('.', (string) round($number,3));
$formatedNumber = $digit->format($numberParts[0]);
if (isset($numberParts[1] ) {
$formatedNumber .= ' and ' . $digit->format($numberParts[1]);
}
return $formatedNumber;
}
@php
echo numberToText(10.557);
@endphphttps://stackoverflow.com/questions/63657875
复制相似问题