[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


No roundup or rounddown

Posted on 2006-04-13
Medium Priority
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
  • 2
LVL 64

Expert Comment

by:Fernando Soto
ID: 16450924
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 64

Accepted Solution

Fernando Soto earned 200 total points
ID: 16450972
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}")


Expert Comment

ID: 16451006
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

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

873 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