No roundup or rounddown

Posted on 2006-04-13
Last Modified: 2010-04-23
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

Question by:inzhagi
    LVL 62

    Expert Comment

    by:Fernando Soto
    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()

    LVL 62

    Accepted Solution

    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}")

    LVL 9

    Expert Comment

    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    I'm currently working for a company where I have to upgrade over 50 VB6 programs to VB.NET 2008.  So far I'm about half way through, and I've learned quite a few tricks that drastically improve the performance of VB.NET apps. Because there are a…
    Article by: Kraeven
    Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    760 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

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now