Tommy
Tommy copied to clipboard
unable to load numbers without decimal places as double
All numbers without decimal places are automatically loaded as integers which makes the implicit cast to double impossible. The only way around is an abomination like this:
double value = _tomlFile["myFloatVal"].IsInteger ? (int)_tomlFile["myFloatVal"] : _tomlFile["myFloatVal"];
Otherwise the implicit operator double(TomlNode value) => value.AsFloat.Value;
will throw an exception.
Is there really no way around this?
I am using .net 6.0 and the Tommy 3.1.2 NuGet package.
Yea. I came looking to see if others have complained about the same thing. It seems like you'd need to make sure any floats or doubles have ".0" if the value has no fractional component.
Even if "TomlNode" had the ability to be type-coerced into a float from whatever it's existing type was, that would be ideal. As long as the value is a number in some way, there shoudn't be any issues. Even if the Toml specifications say "ints look like this and floats look like this".