Round


Node Information
Rounds a double-precision floating-point value to the nearest integral value.
General Information
• This node doesn't have other available options.
• Some of the ports of this node can change their types and accept types automatically.
Visual
Visual

Ports
Text Type DataType Accepts IsList CustomAcception
Value IN Double ONE FALSE TRUE
DecimalsDigits IN Double ONE FALSE FALSE
Result OUT Double MULTIPLE FALSE FALSE

Source
namespace Korduene.KGraph.Nodes.Math
{
    [IsNode("Round")]
    public class MathRound : Node
    {
        Port a = new Port(PortType.IN, typeof(double), AcceptsLinks.ONE, "Value");
        Port des = new Port(PortType.IN, typeof(double), AcceptsLinks.ONE, "DecimalsDigits");
        Port res = new Port(PortType.OUT, typeof(double), AcceptsLinks.MULTIPLE, "Result");
        public MathRound()
        {
            NodeType = NodeType.Function;
            ReturnType = typeof(double);
            a.Value = "0";
            des.Value = "0";
            res.Value = "0";
            this.Name = "Round";
            this.AddPort(a);
            AddPort(des);
            this.AddPort(res);
            a.CustomAcception = Accepts;
            Information = "Rounds a double-precision floating-point value to the nearest integral value.";
        }
        private bool Accepts(Port port)
        {
            if (port == null)
            {
                return false;
            }
            if (a.IsConnected || res.IsConnected)
            {
                if (port.DataType == a.DataType)
                {
                    return true;
                }
            }
            else if (port.DataType == typeof(double) || port.DataType == typeof(decimal))
            {
                ReturnType = port.DataType;
                a.DataType = port.DataType;
                a.Refresh();
                res.DataType = port.DataType;
                res.Refresh();
                return true;
            }
            if (GraphCore.CanConvert(port.DataType, res.DataType))
            {
                return true;
            }
            return false;
        }
        public override string Code()
        {
            return "return Math.Round(" + GetValue(a) + "," + GetValue(des) + ");";
        } 
    }
}