No roundup or rounddown

I have a textfiled named textfield1.text......and the maximum number lenght is 12...

the problem is...if a user enter 12.678 for example then i need the field to accept 12.67..without any roundup or rounddown...

example : 45.789 must be 45.78 only,
               79.435434543 must be only 79.43


inzhagiAsked:
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.

Fernando SotoRetiredCommented:
Hi inzhagi;

This code will do what you want with the use of Regular Expression.

Imports System.Text.RegularExpressions

        Dim newValue As String
        Dim m As Match

        m = Regex.Match(TextField1.Text, "\d+\.\d{1,2}")
        'New Value holds the value you want
        newValue = m.Value()


Fernando
0
Fernando SotoRetiredCommented:
Hi inzhagi;

One small change to my above code. I had changed the pattern so that the return string would be 123 for input 123, 123.4 for 123.4, 123.45 for 123.45 and 123.45 for values as 123.4567890.

    m = Regex.Match(TextField1.Text, "\d+(?:\.\d{1,2}){0,1}")

Fernando
0

Experts Exchange Solution brought to you by

Your issues matter to us.

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

Start your 7-day free trial
jrschererCEOCommented:
If you want to do it on the number, not on the string then do something like this:
          Dim m As Double = 79.435434543
          Dim n As Double = (Fix(m * 100.0)) / 100.0
          ' n will hold 79.43 with no rounding
Jack.net
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.