Code/Dependencies/DotNetGraph/Attributes/DotDoubleAttribute.cs
using System.Globalization;
using System.Threading.Tasks;
using Nodebox.Dependencies.DotNetGraph.Compilation;

namespace Nodebox.Dependencies.DotNetGraph.Attributes {
    public class DotDoubleAttribute : IDotAttribute {
        public double Value { get; set; }

        public string Format { get; set; }

        public DotDoubleAttribute(double value, string format = "F2") {
            Value = value;
            Format = format;
        }

        public async Task CompileAsync(CompilationContext context) {
            await context.WriteAsync(Value.ToString(Format, NumberFormatInfo.InvariantInfo));
        }

        public static implicit operator DotDoubleAttribute(double value) => new DotDoubleAttribute(value);
    }
}