Question: What is the correct way to perform this operation?

```
399.9 / 100

```

What I would expect to see is

```
3.999

```

but the result is

```
3.9989999999999997

```

Answer: 
The result you see is *correct*, it's just not what you want.

Doubles are not precise values. The double you get by writing 399.9 is actually the precise value. 

> 
> 399.8999999999999772626324556767940521240234375
> 
> 
> 

That's the closest available double to the exact value 399.9. Any other double is at least as far away from 399.9 as that.

Then you divide by 100. Again, the result is not precise, but the closest double has the exact value

> 
> 3.99899999999999966604491419275291264057159423828125
> 
> 
> 

That differs from what you would get by writing 3.999, which is the exact value:

> 
> 3.999000000000000110134124042815528810024261474609375
> 
> 
> 

At every step, the double operations have minimized the error, but because you are doing multiple steps, the final result diverges from the double closest to the mathematical result.

What you need to do depends on what your actual requirements are.

If you want to always calculate with two significant digits, then I'd just multiply my numbers with 100 and do all the operations as integer operations, until the very last division by 100.

If you have an intermediate result and wants to round it to two digits, I'd do what Fy Z1K says:

```dart
  result = (result * 100).round() / 100;

```
To make decimal operations you can use the [decimal package](https://pub.dev/packages/decimal).

```
final d = Decimal.parse;
print(d('399.9') / d('100')); // => 3.999

```