How to round a decimal number to another nearest decimal?

Asked

Viewed 43 times

2

So people are having a hard time creating a discount calculator. For example: I want a number x = 2,27 turn 2.3 and x = 2,24 stay 2.2.

How to do this?

  • This may also be useful: http://answall.com/a/21941/101

  • A simple way is you create a variable of type decimal to receive these values and when presenting them you use the function ToString(), looks something like this: variable declaration decimal numero = 0; attribution of the value to it numero = 1.33M; obtaining the rounded value: MessageBox.Show(numero.ToString("N1")); //Resultado: 1,3, another example: numero = 1.35M; outworking: MessageBox.Show(numero.ToString("N1")); //Resultado: 1,4

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.