Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre

Notices

Reply
 
Thread Tools Search this Thread
Old 03-28-2013, 03:01 PM   #1
oelgamal
Junior Member
oelgamal once ate a cherry pie in a record 7 seconds.oelgamal once ate a cherry pie in a record 7 seconds.oelgamal once ate a cherry pie in a record 7 seconds.oelgamal once ate a cherry pie in a record 7 seconds.oelgamal once ate a cherry pie in a record 7 seconds.oelgamal once ate a cherry pie in a record 7 seconds.oelgamal once ate a cherry pie in a record 7 seconds.oelgamal once ate a cherry pie in a record 7 seconds.oelgamal once ate a cherry pie in a record 7 seconds.oelgamal once ate a cherry pie in a record 7 seconds.oelgamal once ate a cherry pie in a record 7 seconds.
 
Posts: 3
Karma: 1806
Join Date: Mar 2013
Device: laptop
Smile Rounding to nearest integer in Custom Column - Hijri Year

Hello,

I have a column for the year the book was written in the Gregorian calendar, and also another column for the year in the Hijri Lunar calendar

I called the first column gyear, and the second column hyear. they are related by the simple formula hyear = (33/32)*(gyear - 622)

So made a column built from other columns, and called it hyear and gave it the following template,

Quote:
{#hyear:'multiply(divide(33,32),subtract(field('#g year'),622))'}
and it works fine, except the result is a float with 4 decimal places, and I want to round it to the nearest integer. I tried

Quote:
{#hyear:'format_number(multiply(divide(33,32),subt ract(field('#gyear'),622)),'{0:d}')'}
to do this but it does not work, it simply shows blank.

Please let me know how to do this, I am sure it is a very simple feature I simply overlooked.

P.S. I posted this under the wrong section previously.

Thanks
oelgamal is offline   Reply With Quote
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: 11,741
Karma: 6997045
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
Advert
Old 03-28-2013, 07:12 PM   #3
oelgamal
Junior Member
oelgamal once ate a cherry pie in a record 7 seconds.oelgamal once ate a cherry pie in a record 7 seconds.oelgamal once ate a cherry pie in a record 7 seconds.oelgamal once ate a cherry pie in a record 7 seconds.oelgamal once ate a cherry pie in a record 7 seconds.oelgamal once ate a cherry pie in a record 7 seconds.oelgamal once ate a cherry pie in a record 7 seconds.oelgamal once ate a cherry pie in a record 7 seconds.oelgamal once ate a cherry pie in a record 7 seconds.oelgamal once ate a cherry pie in a record 7 seconds.oelgamal once ate a cherry pie in a record 7 seconds.
 
Posts: 3
Karma: 1806
Join Date: Mar 2013
Device: laptop
Thank you very much, it works now! I would not have found it on my own.

I think may be a small section in the documentation section with sample uses would be nice.

peace
oelgamal is offline   Reply With Quote
Reply

Tags
custom column, format, template language


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Rounding to nearest integer in Custom Column - Hijri Year oelgamal Recipes 0 03-28-2013 02:58 AM
Custom yes/no column built from long text column Philantrop Library Management 7 03-23-2013 07:44 PM
how to move value(s) of tag column to a custom made column zoorakhan Library Management 0 12-08-2012 03:53 AM
custom date column from two state column Dopedangel Library Management 7 01-03-2012 08:20 AM
Can custom book data be displayed in a custom column? kiwidude Development 9 03-02-2011 05:35 AM


All times are GMT -4. The time now is 09:17 PM.


MobileRead.com is a privately owned, operated and funded community.