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?
Printable View
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?
If there is a possibility to change your type to decimal without a narrowing convertion you could use the Decimal classes Truncate method:
/LeyanCode:Dim a As Double = 467.923
MsgBox(Decimal.Truncate(CType(a, Decimal)))
Yeah its Math.Round:
VB Code:
MsgBox(Math.Round(4.9, 0))
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
You can convert it to Int() if you just want to round down or drop the decimals.
MsgBox(Int(1.1))
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
Thanks!
hmm in C# int(1.1) seems not to work =(
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);
}
aah there is a SPECIFIC function for this! why dont you use this:
math.floor ()
there is also a math.ceiling function
ah lol..but now the function is done :eek:
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:D:D
lool whatever =P