xperience Gallery

Code Golf: Count formula

Time to play a little code golf, where we try to find the shortest possible source code to accomplish a given task. I’m going to be taking on a formula in Crystal Reports that changes a running total {#Count} into a text string to be used as a line label. The string should be formatted with an numeral followed by a period.

Gallery Systems uses the following formula in their reports, based upon the ToText function that converts an integer, and then uses string processing to strip away the two decimal places:

1
Left(ToText({#Count}),Length(ToText({#Count}))-2)

Here is my submission, which uses the same ToText function, but employs the optional parameter that specifies the number of decimal places, and then concatenates the period to the end:

1
ToText({#Count},0)+"."

Do you have a submission, or your own variation? Comment it below!

Thanks for taking the time to read my post – I hope you found it helpful.
Leave feedback in the comments below.

If this post save you time, then consider sharing it with your friends and colleagues. If it saved you some money, then please consider buying me a coffee. If you want to know when I publish new content, then subscribe to my feed. Your support encourages me to write more. Thanks!

Leave a Comment