View Single Post
Old 03-28-2013, 06:01 PM   #2
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,455
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
The problem is that you are using the characters { and } in the template in template program mode. Those characters are special. In single function mode or in template program mode, anything between { and } is evaluated before the template itself is evaluated. I realize that this fact isn't made clear by the documentation. It is mentioned in the docs for the eval function, but that might not help much. I will look at fixing this lack. But regardless ...

If you want to use the { and } characters in a template, which you must do if you are using format_number, then you must use general program mode. A GPM template that computes what you specify is
Code:
program: format_number(multiply(divide(33,32),subtract(field('#gyear'),622)), '{0:.0f}')
However, note that there is no guarantee that the result is rounded. If you want to be certain to round, then you should add 0.5 to the result before you format it.

If this template will be used in a composite custom column then I suggest you precompute 33/32 to whatever precision you want and use that number. There is no point in recomputing that number for every book. which is what the template would do if the divide is left in.

Last edited by chaley; 03-28-2013 at 07:14 PM. Reason: clarifications
chaley is offline   Reply With Quote