2

I want to use doubles in my code but Dart converts them to ints (or dynamic).

I have tried to cast them using 'as' or .toDouble() but they do not stay as doubles:

(in dartpad)

main() {
  print ((1.0 as double).runtimeType);
  print (1.0.toDouble().runtimeType);
}

(output)

int
int

I would have expected the output of these statements to be 'double'. If I change the value to 1.1 I get a double out.

David New
  • 21
  • 2
  • 1
    Read this answer: https://stackoverflow.com/a/43954219/8745788 this happens only in dart2js, eg. running the dart sdk with this code works as expected – Mattia Oct 09 '19 at 20:25

0 Answers0