Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Remove decimal places in text box value

Posted on 2006-07-20
17
Medium Priority
?
705 Views
Last Modified: 2012-01-05
Dear All ,

Please help me for this simple question .

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.


0
Comment
Question by:PChandima
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
  • +2
17 Comments
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 17144785
try:

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

Accepted Solution

by:
Ryan Chong earned 200 total points
ID: 17144793
May try this instead:

text2.text = fix(text1.text)
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 17144799
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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:PChandima
ID: 17144857
Dear Ryancys

Thanks For your comments

PChandima
0
 
LVL 20

Expert Comment

by:alainbryden
ID: 17145932
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
0
 
LVL 20

Expert Comment

by:alainbryden
ID: 17146034
[If you're going straight back to a string then: Text2.text = Int( text1.text ) ]
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 17147061
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!
0
 
LVL 20

Expert Comment

by:alainbryden
ID: 17148202
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
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 17148235
no worries ; )
0
 
LVL 15

Expert Comment

by:Ryan_R
ID: 17151678
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
0
 

Expert Comment

by:smokey965
ID: 17164023
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.
0
 
LVL 15

Expert Comment

by:Ryan_R
ID: 17164480
did you try it with "123.999"?
it appears that he always wants to round the number down
0
 
LVL 20

Expert Comment

by:alainbryden
ID: 17164705
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
0
 
LVL 15

Expert Comment

by:Ryan_R
ID: 17172071
is there a vb function like the one in excel called ROUNDDOWN() ?
0
 

Expert Comment

by:smokey965
ID: 17172111
Here's another one 'text1.text = split(text1.text, ".")(0)'
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question