# Remove decimal places in text box value

Dear All ,

I have text box value like given below .

Text1.text = 12.75

From this value I want to get whole number only .

Ex. text2.text = 12

Thanks

PChandima.

###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

try:

text2.text = format(text1.text, "0")

text2.text = fix(text1.text)

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

a better handling.. just in case the value of text1 is non-numeric:

if isnumeric(text1.text) then
text2.text = fix(text1.text)
else
text2.text = "0" 'or default value
end if
Author Commented:
Dear Ryancys

PChandima
Commented:
Lol you guys are rediculous! It's so much simpler than that.

Dim number As Integer
number = Int(Text1.text)   'Visual basic automatically TRUNCATES when creating integers

'''Assume Text1.text = 12.99999
'''Then number = 12
'''Careful, because if Text1.text = -45.01827
'''Then number = -46
'''(negative numbers round down)

alain
Commented:
[If you're going straight back to a string then: Text2.text = Int( text1.text ) ]
Int, Fix Functions
http://msdn2.microsoft.com/en-us/library/t4dseb50.aspx

>>number = Int(Text1.text)
yes, this will work IF and ONLY when Text1.text is a numeric value, else a Type Mismatch error will appear.

>>Lol you guys are rediculous!
Frankly, we are just volunteer to help here, however i don't expect to get that as a response here!
Commented:
If isNumeric(Text1.text) then number = Int(Text1.text)

Didn't mean to offend you. I suppose that was innapropriate and appologize, I was simply explaining that there were more simple means.

Alain
no worries ; )
easiest way would be to use the Left() function

ie txt1.text = Left(txt1.Text, InStr(txt1.Text, "."))
if necessary use the CStr() function to convert to string but i don't think you'll need to
Commented:
An easier way would be
text1.text = "123.456"

text1.text = text1.text + 0

That will make text1.text = "123"

This works on my computer.
did you try it with "123.999"?
it appears that he always wants to round the number down
Commented:
smokey's solution is effectively using the Int ( ) function, because it typecasts text1.text as an integer to match the type of "0" which is integer.

Ryan's solution has the same effect as the Fix() function, although it is not nearly as fast. String functions take much much longer to execute then a simple truncation function. A one time use case doesn't matter though. Only if this were code used alot in a loop or recursive call.

Alain