php NumberFormatter 格式拼写

php NumberFormatter format to spelling

嗨,我在 laravel 中使用 php NumberFormatter 现在如果我想回显号码我做了这个代码

@php
   $digit = new \NumberFormatter(Lang::locale(), \NumberFormatter::SPELLOUT);
   echo $digit->format(round(10.557,3));
@endphp

结果会是 但我需要它

ten and five handred and seventy five

如何更改格式.. 谢谢..

您可以尝试手动构建一个函数

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);
@endphp