Home > Back-end >  How to display fractional part of a decimal in tens in French
How to display fractional part of a decimal in tens in French

Time:09-22

I want to display a decimal in words in French. I succeeded doing that using the NumberFormatter class.
Here's my code

$dec_words = new NumberFormatter("fr", NumberFormatter::SPELLOUT);

echo $dec_words -> format(20.17);

The output was vingt virgule un sept instead of vingt virgule dix-sept

Please how can I fix this? Thanks

CodePudding user response:

vingt virgule un sept is correct though. It's just another way to say it. "twenty point one seven" vs "twenty point seventeen"

With that said, you could split the number in two on the decimal and run both halves through the formatter.

$dec_words = new NumberFormatter("fr", NumberFormatter::SPELLOUT);

$n = 20.17;
$components = explode(".", "$n");
echo $dec_words -> format($components[0]);
if(count($components) > 1)
{
    echo " virgule ";
    echo $dec_words -> format($components[1]);
}

Output: vingt virgule dix-sept


It could be just an English thing that's being carried over to other languages, but we generally say each decimal point as its digit in English rather than saying the decimal as a full number.

I've never heard anyone call PI (3.141...) "three point fourteen" or "three point one hundred forty-one.". We always say "three point one four" or "three point one four one."

  •  Tags:  
  • php
  • Related