Erro de calculo do c$

Fabio Luiz 0 Reputation points

Captura de tela 2023-08-30 104204

Captura de tela 2023-08-30 104721

Conforme imagens acima, tenho um calculo da variavel tef.valor * 100, o valor da variavel conforme segunda imagem é de 589.8. 589.8 * 100 = 58980, porem o c# ta apresentando o resultado 58979,999999... Alguem pode me dizer pq acontece este erro de calculo?

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,164 questions
{count} votes

1 answer

Sort by: Most helpful
  1. P a u l 10,401 Reputation points

    There are limitations in the precision of float and double values due to the way they're stored in memory:

    If you require a higher precision, or if you're working with numbers that can't be accurately stored in a binary fraction then you could consider casting the number as a decimal ((decimal) tef.Valor) instead.

    0 comments No comments