I know this is an old thread, but there is no answer that I could find, so here is my posting of a possible fix.
I was experiencing this same problem when trying to use cdef. The current reported "correctly" but the last was negative.
I'm no coder, but i did figure out that in the poller.php, line 101 calls for the calculation of current value, referencing "thold_get_currentval" in thold_functions.php, that result was a giant negative number which then gets passed into the switch below and messes up my cdef, resulting in the messed up "last" value.
The following is what I did to fix the problem when it relates to using cdef.
on line 101 in the /include/poller.php file,
$currentval = thold_get_currentval($t_item, $rrd_reindexed, $rrd_time_reindexed, $item, $currenttime);
$currentval = get_current_value($t_item['rra_id'], $t_item['data_id'], $cdef = 0);
This resulted in passing the correct "current value" into the cdef function which for me resulted in the proper Percentage of the link that i wanted.
Again, I'm no coder, but I was able to follow the trails which led me to use the same function that is referenced for the "current" display and then figured out which values to pass into it and it worked for me. I don't recommend just apply this to a production system without first testing in a lab of your own.
Here is a picture showing it working on a 10g interface.
cdef cacti fix proof.png [ 14.08 KiB | Viewed 6562 times ]