By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,814 Members | 1,671 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,814 IT Pros & Developers. It's quick & easy.

rounding float toward zero?

P: n/a
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.
May 9 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On May 9, 4:23 pm, "Yasin cepeci" <cep...@gmail.comwrote:
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

May 9 '07 #2

P: n/a
Use,

Math.Floor

"Yasin cepeci" <ce****@gmail.comwrote in message
news:em**************@TK2MSFTNGP03.phx.gbl...
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.

May 9 '07 #3

P: n/a
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Yasin cepeci" <ce****@gmail.comwrote in message
news:em**************@TK2MSFTNGP03.phx.gbl...
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.

May 9 '07 #4

P: n/a
On May 9, 4:32 pm, "Ignacio Machin \( .NET/ C# MVP \)" <machin TA
laceupsolutions.comwrote:
Use,

Math.Floor
That would round -0.5 to -1, which isn't what the OP wants, as far as
I can tell.

Jon

May 9 '07 #5

P: n/a
it works thank you so much . happy days
"Jon Skeet [C# MVP]" <sk***@pobox.com>, haber iletisinde sunlari
yazdi:11**********************@p77g2000hsh.googleg roups.com...
On May 9, 4:23 pm, "Yasin cepeci" <cep...@gmail.comwrote:
>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

May 9 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.