|
-
Nov 22nd, 2002, 10:07 AM
#1
Thread Starter
yay gay
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/
-
Nov 22nd, 2002, 10:42 AM
#2
Registered User
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
-
Nov 22nd, 2002, 11:48 AM
#3
Yeah its Math.Round:
VB Code:
MsgBox(Math.Round(4.9, 0))
-
Nov 22nd, 2002, 12:07 PM
#4
Registered User
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
-
Nov 22nd, 2002, 12:23 PM
#5
You can convert it to Int() if you just want to round down or drop the decimals.
MsgBox(Int(1.1))
-
Nov 22nd, 2002, 12:29 PM
#6
Registered User
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
-
Nov 22nd, 2002, 12:31 PM
#7
-
Nov 22nd, 2002, 12:32 PM
#8
Thread Starter
yay gay
hmm in C# int(1.1) seems not to work =(
\m/  \m/
-
Nov 22nd, 2002, 12:51 PM
#9
Thread Starter
yay gay
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/
-
Nov 22nd, 2002, 07:05 PM
#10
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!!
-
Nov 22nd, 2002, 07:48 PM
#11
Thread Starter
yay gay
ah lol..but now the function is done
\m/  \m/
-
Nov 22nd, 2002, 08:01 PM
#12
-
Nov 22nd, 2002, 08:05 PM
#13
Thread Starter
yay gay
\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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|