Skip to content

1.0 is int not double in dart web. #34105

Closed
@CaiJingLong

Description

@CaiJingLong

1.0 is int not double in dart web.

~ dart --version
Dart VM version: 2.0.0 (Fri Aug 3 10:53:23 2018 +0200) on "macos_x64"

same code

const str = """{"num1":1.0,"num2":1.1}
    """;

  var map = json.decode(str);
  var n1 = map["num1"];
  if (n1 is int) {
    print("is int");
  } else if (n1 is double) {
    print("is double");
  } else {
    print("is other");
  }
  print(map["num1"].runtimeType);
  print(map["num2"].runtimeType);

run in dart vm or flutter then result is

is double
double
double

run in dart web

is int
int
double

What do I do to make 1 recognises double instead of int?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions