Forum Discussion
<#assign string = "Best Answer" />
<#assign bestAnswersCount = count />
<#if bestAnswersCount > 1>
<#assign string = "Best Answers" />
</#if>
<#if bestAnswersCount > 999 />
<#assign bestAnswersCount = '1k' />
</#if>
<li class="item">${bestAnswersCount} ${string}</li>
- BowBharath8 years agoAce
I am learning....Thank you VikasB . The string best answers works awesome. Now i am worried about 1K...2K...2.2K....1L
Thinking about more generic code.
- VikasB8 years agoBoss
BowBharath I think in rare cases answer count may cross this limit. So you can use it
<#assign string = "Best Answer" /> <#assign bestAnswersCount = count /> <#if bestAnswersCount > 1> <#assign string = "Best Answers" /> <#elseif bestAnswersCount > 999 /> <#assign bestAnswersCount = "1k" /> <#elseif bestAnswersCount > 1999 /> <#assign bestAnswersCount = "2k" /> <#elseif bestAnswersCount > 2999 /> <#assign bestAnswersCount = "3k" /> <#else> <#assign bestAnswersCount = "3k+" /> </#if> <li class="item">${bestAnswersCount} ${string}</li>
LMK If you think it can cross it. If yes, I'll try to find you a better solution.
- TariqHussain8 years agoBoss
VikasB - There could be multiple cases which you can not handle by if else.
e.g
1.2k,1.4k,1.5, 2.3k and so on.
<#assign string = "Best Answer" /> <#assign bestAnswersCount = count /> <#if bestAnswersCount > 1> <#assign string = "Best Answers" /> <#elseif bestAnswersCount > 999 && bestAnswersCount < 1000000 /> <#assign bestAnswersCount = (count/1000)?c + "1K" />
<#else>
<#assign bestAnswersCount = (count/1000000)?c + "1M" /> </#if> <li class="item">${bestAnswersCount} ${string}</li>Above example will work for any number e.g 1500 will be 1.5K, 1500000 will be 1.5M. I have added condition for thousand and millions, you can customize it more if needed.
Related Content
- 12 years ago
- 11 years ago