View Single Post
Old 06-25-2019, 11:05 AM   #7
thiago.eec
Wizard
thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.
 
Posts: 1,234
Karma: 1419583
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite, Kindle Oasis
Quote:
Originally Posted by Soap-dodger View Post
Apart from one use case, this works, returning a floating point value. I need to work out how to round the returned value to a whole number, though.

The only time it doesn't work is when both #words and #pages contain null values. In this case, I get the following error message:

Code:
EXCEPTION:  float division by zero
Can you help solve these issues?
Starting with the code posted by @davidfor, you could use something like the code below to format numbers as integers and use 'undefined' instead as '0', since those will appear on the book details pannel (that bothers me ).

Code:
program:
    pages = cmp(raw_field('#pages'),0,1,1,raw_field('#pages'));
    words = cmp(raw_field('#pages'),0,0,0,raw_field('#words'));
    wpp = format_number(divide(words,pages),'{0:.0f}');
    cmp(wpp, 0, '', '', wpp)

Last edited by thiago.eec; 06-25-2019 at 03:07 PM.
thiago.eec is offline   Reply With Quote