Round down whole numbers

Last post 12-18-2005 4:42 AM by master4eva. 1 replies.

Sort Posts:

  • Round down whole numbers

    12-18-2005, 12:30 AM
    • Member
      580 point Member
    • littlevamp
    • Member since 07-04-2005, 4:48 AM
    • Posts 118
    Hi,
      I want to round down whole numbers such as 315, 324 to 300 and instead of rounding up 356, 398 to 400, I want to round down to 300. How do I do so? Can someone please help? Thanks! And the codes I needed is for VB.NET 2003 (code-behind part) and not JavaScript or C# or C++

  • Re: Round down whole numbers

    12-18-2005, 4:42 AM
    • Star
      13,635 point Star
    • master4eva
    • Member since 12-06-2002, 9:54 AM
    • Durban, South Africa
    • Posts 2,719
    For this instance of three digit number, you could do something like this:
     
    dim a As Decimal = Decimal.Floor(input / 100) * 100
     
    For a more generic approach, you could have something like this
     
    public function MyFloor(input as decimal) as decimal
        dim places as integer = Convert.ToInt32(input).ToString().Length;
        Return Decimal.Floor(input / (10 ^ places)) * (10 ^ places))
    end function
     
    The last part just solely depends on your requirements.
    -- Justin Lovell
Page 1 of 1 (2 items)