How to restrict expression output to 2 decimal places in Watson Conversation? - ibm-watson

I have the following expression working correctly in a dialog node in Watson Conversation where the expression is used in a response to a user:
<? ($total_balance * $acceptable_offer) ?>
I need to restrict the output to 2 decimal places. I tried appending toFixed(2) to the expression in the following format but it did not work:
<? ($total_balance * $acceptable_offer).toFixed(2) ?>
How can I edit the expression so that the result displays correctly with only 2 digits?

Simply Use:
<? T(Math).round($total_balance * $acceptable_offer * 100.00)/100.00?>
T(Math) is a new feature in Watson conversation to perform simple maths operations.

Related

Passing Array data using SESSION

I am trying to pass a Single/Multi Dimensional array to a second page using SESSION. I read and tried all questions and answers but can not get it done. Here is the 1st page:
<?php
// SendIt.php
SESSION_START();
$iA=array('A1','A2','B2','B1','B3','A3');
print_r($iA);
$_session['iA'] = $iA;
echo '<br>Click to send the array.';
?>
Here is the 2nd Page:
<?php
// GetIt.php
SESSION_START();
$iB = $_SESSION['iA'];
print_r($iB);
echo 'I am Here...';
?>
I do not get any of the iA array in the second page.
I must be missing something simple. Please check it out. Thx
I got help from a different PHP forum site and was advised that: Like any other PHP variable, _SESSION is case sensitive. So the problem is fixed by matching _SESSION variables and making them all upper case.

Django CommaSeperatedIntegerField and negative numbers

If I had the following class:
class foo(models.Model):
list = models.CommaSeparatedIntegerField(max_length=255)
If I try to add a foo object from the admin, it will not let me populate list with negative numbers. For instance, if I populate the field with 1,2,3,4 its fine. But 1,2,3,-4 will give me the error message "Enter only digits separated by commas." Any ideas?
Thanks!
The validation code of CommaSeparatedIntegerField looks like this:
comma_separated_int_list_re = re.compile('^[\d,]+$')
validate_comma_separated_integer_list = RegexValidator(comma_separated_int_list_re, _(u'Enter only digits separated by commas.'), 'invalid')
So you can't use it for negative numbers.
I suggest you write your own validation code based on this code.

CakePHP 2.0 AclExtras Prints HTML code in shell

I am trying to setup ACL based on the tutorial in the 2.0 book, but I get HTML script when i run
./Console/cake AclExtras.AclExtras aco_sync
It's really long to post here. In my bootstrap.php file I have
CakePlugin::load('AclExtras');
And in my AppController i have
App::uses('Controller', 'Controller');
I have also tried to go without inputting the plugin to see what happens, and when i do something like this:
$this->Acl->allow($group, 'controllers');
I get this error:
Warning (512): DbAcl::allow() - Invalid node [CORE\Cake\Model\Permission.php, line 176]
Any suggestions on how to make this work?
Thanks in advance
Make sure your ACO table is populated with atleast an entry 'controllers', with no parent_id.
Make sure the first argument of allow is a valid argument, in your case, $group should be a Group object, set with a proper group ID. E.g.
$group = $this->User->Group;
$group->id = 1;
(if you only set $group to be an integer, you're definitely going to get the error you're getting, so be sure to check this!)
Make sure the second argument is a valid argument (valid alias for example).

Drupal 7 - node custom display

I've got this problem. I've created file node--mycontenttype.tpl.php to display nodes in custom way. I've listed all the $content array by print_r($content). I can display all the variables except CCK fields. For example I can print out node type like:
<?php print $content['body']['#bundle']; ?>
But if I try to display any CCK field like:
<?php print $content['body']['#object']->field_url[und][0]['value']; ?>
It gives me an error "Notice: Use of undefined constant und - assumed 'und' w include()". Alright, so the "und" means "undefined" for langauge, but nor 'pl', nor 'en' solves the problem. How can I manage this?
Alright, after researching I've finally found an answer. It works, but in some cases it look a bit inefficient. Code goes like this:
<?php
$output = field_get_items('node', $node, 'field_url');
$output = $output[0]['safe_value'];
print $output;
?>
But if you have a lot of CCK fields it looks like you have to launch field_get_items() function a lot of times. If any of you knows a better approach it could be nice you could share.
When you write [und] Drupal (PHP) assumes that there's variable $und defined somewhere in the code.
You should use:
<?php print $content['body']['#object']->field_url['und'][0]['value']; ?>

Drupal 7 Computed field

I am learning Drupal 7 computed field. According to web sources they say i should use $entity instead of $node for Drupal 7.
I have a content type product with custom fields field_price and field_discount. I need a computed field field_finalprice = field_price - field_discount.
As a first step I am just trying to assign field_discount to my finalprice so I created a computed field with code
$entity_field[0]['value'] = array_pop(array_pop(field_get_items($entity_type, $entity, 'field_discount')));
I do not get any value. Please provide any links that uses computed field for drupal 7.
There is an update in the comments IIRC http://drupal.org/node/1271050
$entity_field[0]['value'] = $entity-> field_price[LANGUAGE_NONE][0]['value'] - $entity-> field_price[LANGUAGE_NONE][0]['value']
should work

Resources