Tommy icon indicating copy to clipboard operation
Tommy copied to clipboard

unable to load numbers without decimal places as double

Open BluBb-mADe opened this issue 2 years ago • 1 comments

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.

BluBb-mADe avatar Apr 13 '22 07:04 BluBb-mADe

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".

Andrew900460 avatar May 09 '23 06:05 Andrew900460