Jump to content

[Dúvida] Math.Round


Recommended Posts

Math.Round(3.44, 1) 'Returns 3.4.

Math.Round(3.45, 1) 'Returns 3.4.

Math.Round(3.46, 1) 'Returns 3.5.

Math.Round(4.34, 1) ' Returns 4.3

Math.Round(4.35, 1) ' Returns 4.4

Math.Round(4.36, 1) ' Returns 4.4

Tem a ver com o valor anterior ser par ou ímpar

se for par arredonda para baixo, se for ímpar arredonda para cima

O comportamento desse método segue o padrão IEEE 754

Link to comment
Share on other sites

Bem, visto que nesta framework nao existe o MidpointRounding, a solução que arranjei foi  somar 0.0001 à variavel que queria arredondar. Por exemplo:

decimal variavel = 0.6050;

totaldoc = variavel + 0.0001; //ficava 0.6051

totaldoctextbox.text = Convert.ToString(Math.Round(variavel,2));

e assim já funciona.

Muito obrigado pela ajuda de todos. Abraço

PS: Podem encerrar o tópico

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.