Results 1 to 13 of 13

Thread: numbers

  1. #1

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729

    numbers

    i think this is very easy...isnt there a function that if i have a numbers like 4,3 4,5 4,6 4,9 it will always round it to 4? or 1,5 1,7 1,2 1,1 it will always round to 1?
    \m/\m/

  2. #2
    Registered User
    Join Date
    Nov 2002
    Location
    Växjö, Sweden
    Posts
    314
    If there is a possibility to change your type to decimal without a narrowing convertion you could use the Decimal classes Truncate method:

    Code:
    Dim a As Double = 467.923
    MsgBox(Decimal.Truncate(CType(a, Decimal)))
    /Leyan

  3. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Yeah its Math.Round:

    VB Code:
    1. MsgBox(Math.Round(4.9, 0))

  4. #4
    Registered User
    Join Date
    Nov 2002
    Location
    Växjö, Sweden
    Posts
    314
    Unfortunately the Math.Round function rounds to the nearest number, it's not rounding down only, as I think PT Exorcist wanted if I understood him correctly.

    /Leyan

  5. #5
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    You can convert it to Int() if you just want to round down or drop the decimals.

    MsgBox(Int(1.1))

  6. #6
    Registered User
    Join Date
    Nov 2002
    Location
    Växjö, Sweden
    Posts
    314
    Ahhh, easier than my convert to decimal thing. I tried CInt(4.9) but thet rounded up, missed the Int(4.9) one.

    Nice Edneeis.

    /Leyan

  7. #7
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Thanks!

  8. #8

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    hmm in C# int(1.1) seems not to work =(
    \m/\m/

  9. #9

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    already did my own function lol...
    PHP Code:
    public static int lowerRound(double number)
    {
        
    string temp Convert.ToString(number);
        
    int pos;

        if (
    temp.IndexOf(",") > -1)
        {
            
    pos temp.IndexOf(",");
        }
        else if(
    temp.IndexOf(".") > -1)
        {
            
    pos temp.IndexOf(".");
        }
        else
        {
            throw (new 
    ArgumentException("The given Number(" number.ToString() + " is not a valid number"));
        }

        
    temp temp.Substring(0,pos);

        return 
    Convert.ToInt32(temp);

    \m/\m/

  10. #10
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    aah there is a SPECIFIC function for this! why dont you use this:

    math.floor ()


    there is also a math.ceiling function
    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!!

  11. #11

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    ah lol..but now the function is done
    \m/\m/

  12. #12
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    hehe, I would still use this one. I'm not sure, but I guess it's faster than using int(), because it's written for this purpose only. You can throw your function in trashcap
    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!!

  13. #13

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    lool whatever =P
    \m/\m/

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