decimal values

davide128

Member
Joined
May 3, 2010
Messages
12
Programming Experience
Beginner
Hello .

I'm trying to limit the number of decimal values to 3 in numbers such
as .3125 but I also have numbers such as .5 which I need to leave as is.

how can I determine if a number is 4 decimal places and cut off the last number.. I don't want to round up either.. .3125 should be .312 not .313 and .5 should stay at .5 and not .500. any help is appreciated..
 
In this case there's no need to use String's whatsoever.

Also this is the function I was thinking:
VB.NET:
Private OverLoads Function ThreePtDecimal(ByVal Number As Double) As Double
    Return (Math.Floor(Number * 1000R)) / 1000R
End Function

Private OverLoads Function ThreePtDecimal(ByVal Number As Decimal) As Decimal
    Return CDec((Math.Floor(Number * 1000D)) / 1000D)
End Function
 
I guess it was a different question..I'm aware that I don't need it..I was just wondering why I couldn't find the substring method but it seems it's in the .net class library..I guess I need to do some more reading cause I'm not too sure what's the difference between the .net method versus what vb.net gives you..I noticed there a UCase and toupper method..so which is which and which one is better?
 
I guess it was a different question..I'm aware that I don't need it..I was just wondering why I couldn't find the substring method but it seems it's in the .net class library..I guess I need to do some more reading cause I'm not too sure what's the difference between the .net method versus what vb.net gives you..I noticed there a UCase and toupper method..so which is which and which one is better?
There isn't a different between .net and vb.net because there isn't a vb.net at all, it's just .net. vb.net is the language, which means syntax, but .net is .net is .net.

Look at the String class, MSDN shows you all of the functions/methods, including .ToUpper(), .ToLower(), .SubString(), .Trim(), .Split(), .Join(), etc..
 
The difference between the Mid() function and the Substring() method:

Mid is 1-based; Substring is 0-based.

Mid takes 3 arguments: 1- the string; 2- the starting location (beginning with 1); 3- the number of characters to include.

Substring takes 2 arguments: 1- the starting location (beginning with 0); 2- the number of characters to include. The string to modify is placed before the dot.

Example to extract the first 2 characters from oldstring and save the result to newstring:

newstring = Mid(oldstring, 1, 2)

newstring = oldstring.Substring(0, 2)



Note: The function posted above (by JuggolaBrotha) using the Math.Floor() method includes the code I had posted earlier.
 
Back
Top