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

matheus matheus at
Wed Oct 21 22:50:27 UTC 2020


import std.stdio, std.conv;
void main(string[ ] args) {
     auto a = (1).to!int;     // this works
     auto b = ("1").to!int;   // this works
     auto c = (1.1).to!int;   // this works and c = 1
     auto d = ("1.1").to!int; // Doesn't work

The forth line gives me:

Unexpected '.' when converting from type string to type int
??:? pure @safe int std.conv.toImpl!(int, 
immutable(char)[]).toImpl(immutable(char)[]) [0x55de76d9b4d7]
??:? pure @safe int!(int).to!(immutable(char)[]).to(immutable(char)[]) 
??:? _Dmain [0x55de76d9986e]


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?

Because for what I see "to!int" converts from: int,real but in 
case of string only when it is a integer representation?


More information about the Digitalmars-d-learn mailing list