Results 1 to 3 of 3

Thread: Round Int to nearest 10 [Resolved]

  1. #1

    Thread Starter
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    Resolved Round Int to nearest 10 [Resolved]

    Hey is there a function that will let me round an int or a double to the nearest 10? Eg say I have 127 I want it rounded to 130, but if its 124 its rounded to 120?

    Thanks
    Last edited by john tindell; Apr 4th, 2005 at 12:39 PM.

  2. #2
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: Round Int to nearest 10

    um I dunno if you can do it with .NET functions, but here's a simple function I wrote"
    Code:
    private int toNearestTenth (int num)
    		{
    			return (int)(Math.Round(num/10.0)*10);
    		}
    it basically devides your number by 10 to make it a decimal number and then rounds it and multiplies back
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  3. #3
    Lively Member
    Join Date
    Mar 2005
    Location
    Dhaka, Bangladesh
    Posts
    102

    Re: Round Int to nearest 10

    Nice Solution !

    Rajib

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width