0

My dart code:

 main()
    {
    print("sample data");
    print(700*0.002);
    print(7000*0.002);
    print(70*0.002);
    }

The output:

sample data
1.4000000000000001
14.0
0.14

Why the output is different in case of 700? How to fix that?

uday
  • 569
  • 1
  • 6
  • 16

1 Answers1

0

This is floating-point aliasing due to their IEEE 754 representation and not unique to dart

Python:

>>> 700*0.002
1.4000000000000001

Just display them with something float-aware and the precision will be right or move your math into an integer space

ti7
  • 16,375
  • 6
  • 40
  • 68