Question about: ("1.1").to!int;

bachmeier no at
Wed Oct 21 23:24:36 UTC 2020

On Wednesday, 21 October 2020 at 22:50:27 UTC, matheus wrote:

> Since (1.1).to!int = 1, shouldn't the string value 
> ("1.1").to!int at least try to convert to float/double and then 
> to int?

I don't think so. A silent string->double conversion isn't IMO 
consistent with D's design.

"1.1".to!!int works fine, and I like that you have to be 
explicit, because there is so much room for error.

Note that "1".to!!int works as expected. Therefore you 
should be able to use that all the time.

More information about the Digitalmars-d-learn mailing list