View Single Post
Old 08-03-2025, 04:40 PM   #852
Far_Pen_6884
Enthusiast
Far_Pen_6884 began at the beginning.
 
Posts: 27
Karma: 10
Join Date: Jul 2025
Device: paperwhite
I'm attempting to display word_count with "K" and "M" suffixes for thousands and millions, respectively. However, I'm encountering an issue saying "TEMPLATE ERROR could not convert string to float". How can I fix the template to work as intended?

Code:
program:
  switch(
    field('#word_count') >= 1000000, format_number(field('#word_count') / 1000000, '{:.1f}') + ' M',
    field('#word_count') >= 1000, format_number(field('#word_count') / 1000, '{:.1f}') + ' K',
    field('#word_count')
  )
Another question. If I were to ask this on Codidact or StackOverflow, what tags should I use? Should I tag it as `calibre template`, or is there a programming language that uses the same syntax that I should tag instead?
Far_Pen_6884 is offline   Reply With Quote