TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Peter
NA
14
26.2k
How to "round" a float to an int?
Jan 4 2011 11:26 PM
Hi
how do I round a float to an int, such that if the decimal part is .5 or more, then the value is rounded up, otherwise the value is rounded down?
For example, 3.2f => 3; 3.5f => 4; 3.7f => 4; 4.2f => 4; 4.5f => 5; 4.7f => 5
If I use (int)Math.Round(3.5f), the result is 4 (ie what I want); whereas with (int)Math.Round(4.5f), the result is 4 (ie not what I want).
Is there a "Math" method which does rounding the way I want it?
Thanks,
Peter
Reply
Answers (
3
)
Looking for c# teacher ! Please help.
combobox problem