netlogoagent-based-modeling

The word function have a problem with decimal values


I'm having a problem with the following code.I would like to display the amount of money of people with the $ sign. In the interface there is a monitor that shows the actual money of an agent, but with the function word it shows to me all the decimal places possible (I inserted 2, but seems it doesn't care). The code is inside the monitor's reporter. Thanks in advance.

word "$" sum [money] of people


Solution

  • When you use the function word, you are no longer displaying a number but rather a string. Because of that, the notion of decimal places no longer applies because you are looking at text. That means you need to change the number of decimals the number has before you turn it into a string. Precision is a primitive that allows you to manipulate the number of decimals. Combining that with your code gives the following:

    word "$ " precision sum [money] of people 2
    

    Displayed below with brackets to make it a bit more clear what happens when.

    (word "$ " (precision (sum [money] of people) 2) )