rounding float toward zero?

  • Thread starter Thread starter Yasin cepeci
  • Start date Start date
Y

Yasin cepeci

Converting single to int Rounds the upper number if the part after dot is
bigger than 0,5. But I want to discard the value after dot.
 
Converting single to int Rounds the upper number if the part after dot is
bigger than 0,5. But I want to discard the value after dot.

I think Math.Truncate(double) is what you're after.

Jon
 
Yasin,

You can pass this to the static Floor method on the Math class.

Generally speaking though, you can use the following formula to find the
floor or ceiling for any number:

floor = round(number - 0.5)
ceiling = round(number + 0.5)

Assuming that rounding will round to the next highest integer for values
of .5 and above.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top