0

I am having issues with the data type float as it is not giving the expected output. Can anyone help or point me to the right direction? See my screenshot about the problem.

As you can see, I'm trying to add 2 floats but the result is 24.599998 instead of just 24.6. Any way to get just 24.6 without rounding? I have also tried removing the f and there is no luck

Neuron
  • 5,141
  • 5
  • 38
  • 59
Christian
  • 1
  • 1
  • 1
    Welcome to SO. Floats are inherently imprecise. computers can only store a limited subset of our real numbers (since computer memory is not infinite). It is counterintuitive which numbers work and which don't, because we display numbers in base 10 while computers work with base 2 – Neuron Oct 13 '21 at 08:02
  • Also please don't post code as a screenshot. This makes your code inaccessible to search engines and people with certain disabilities. Just copy&paste it as a code block – Neuron Oct 13 '21 at 08:04

0 Answers0