View Single Post
Old 11-06-2017, 08:49 AM   #3
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,453
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
If you want to format a composite column (a computed column) then you must do the formatting yourself in the template. I see three ways to do what you want.
  1. Use column icons to show an image of stars based on the value. This would be the way to go if you want half-star images.
  2. Use something like the following:
    Code:
    program:
    # the variable 'v' contains the computed rating
    	v = 3.5;
    # verify that the value <= 5
    	v = cmp(v, 5, v, v, 5);
    # Check if the value is a fraction
    	halfstar = contains(v, '\.', 'y', '');
    # Make the value into an integer (floor)
    	v = re(v, '\..*', '');
    # Get the string with the right number of stars
    	r = cmp(v, 0, '', '', substr('★★★★★', 0, v));
    # Add the 'half' if needed
    	test(halfstar, strcat(r, '½'), r)
    The value 3.5 produces ★★★½
  3. Use a custom formatter function to compute a string containing whatever you want.
chaley is offline   Reply With Quote