WordCount and FuzzyWordCount

  1. What’s the difference? Reading on page variables is not clear.
  2. Which is more accurate? The first pulls lesser number than the latter.

.FuzzyWordCount rounds up to the nearest multiple of 100, primarily to display something friendly (300) instead of something that no one cares about (287).

Alright. So, if it was between 201 and 249, will .FuzzyWordCount show 200 or 300?

At 201 it will show 300.

If you want to round to the nearest 100:

{{ mul (math.Round (div (float .WordCount) 100)) 100 }}

Alright. Where I come from, math was taught that anything below 5 in a tens digit is rounded down, hence my question. So 201-249 would round off to 200. But now I see Hugo works only with rounding up (by default?).


How you decide to round a number depends on how you… round.

See https://gohugo.io/functions/math/

  • math.Ceil
  • math.Floor
  • math.Round

You’ll find these same functions (perhaps named differently) in most programming languages.

When .FuzzyWordCount was implemented as a method on .Page, the decision was to round up. If you don’t like that, use the code from my previous response.

1 Like

That worked! I prefer that solution. I will document it for current and future purposes. Thanks.

The last question is, does the .WordCount include or exclude punctuation?

Why don’t you try it yourself? Experimentation is a great way to learn.

word --> 1
word word --> 2
word. word --> 2
word. word. --> 2
1 Like

I will test once I am on PC. Cheers!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.