0

I have a dialog node in my Watson Assistant that takes a number provided by the user and then provides a response with that number used in a division like so:

<? (1000 * ($Number / 6.00)) ?> Grams

The problem is that this returns a message like this: (Considering the number was 2)

333.3333333333333 Grams

Removing the .00 from the 6.00 results in:

0 Grams

Is there any way I can round the result of the division? Ideally I would like to round it to the nearest multiple of ten but rounding it to 2 decimal places would also be acceptable. I want to get a final message like so:

333.33 Grams
data_henrik
  • 16,724
  • 2
  • 28
  • 49
IvanHid
  • 669
  • 7
  • 25

1 Answers1

0

You could use one of the round() methods provided by ava.lang.Math. Watson Assistant allows those methods in the input processing. Depending on how many fractions you need, you would need to "massage" the numbers. There are round() methods for float and double. You could first apply toDouble() to make sure the number is treated correctly.

Note that there is a discussion on how to perform exact and efficient rounding in Java.

data_henrik
  • 16,724
  • 2
  • 28
  • 49