Formatting a decimal for speech

Has anyone built a Jinja macro or similar that can be used to convert decimals to a format that makes sense when spoken?

I have yesterday’s rainfall spoken when I wake up. I’ll get something like “it rained zero point zero five inches yesterday” or “it rained zero point five”…

I’d like to instead hear “it rained five hundredths of an inch” or “it rained half an inch”.

I can conceive of doing this with a bunch of if/then statements in my template, but I’m wondering if someone’s handled this more cleanly / robustly.

I personally would not do it but you could just convert it to mm and not worry about decimals.

So would you only want to state the decimal places if it was less than an inch?

I think If/Then is simple enough and I don’t see the need for precision over an inch. That way you could just do the conversions for everything <1"; unless you want to be more natural and say ‘half inch’.

For the TTS items (even if you don’t use these) look at Node Red flows or Rhasspy syntax that others use.

I never thought about this a TTS issue, but I may add it to one more thing to do.
You made me look to see how many significant digits I had for rain fall; so 1/100ths is will work.

There are decimal to fraction calculators that would probably be what you want.