473,406 Members | 2,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How to get Decimal Points in Numeric Value

Mohan Krishna
115 100+
Hi everyone!

I am entering only numbers with decimal points/values in a TEXTBOX on the VB form. I need to get only the decimal values.

How can I? Please help me as I tried in this way (for 2 Decimal places)

Expand|Select|Wrap|Line Numbers
  1.  VB6
  2.         Dim x As Double
  3.         Dim dc As Integer, dcStr As String
  4.  
  5.         x = Val(Text1.Text)
  6.         dc = InStr(x, ".")
  7.         If dc > 0 Then
  8.             dcStr = Left(Mid(Text1.Text, dc + 1) & "00", 2)
  9.         End If
  10.  
ThnQ all !
Nov 22 '07 #1
6 16616
Mohan Krishna
115 100+
Hi everyone!

I am entering only numbers with decimal points/values in a TEXTBOX on the VB form. I need to get only the decimal values.

How can I? Please help me as I tried in this way (for 2 Decimal places)
:
:
ThnQ all !
Also can I restrict to enter only 2 decimal places?
I tried this code in TEXT_CHANGE()
Expand|Select|Wrap|Line Numbers
  1.         Dim x As Double
  2.         Dim dc As Integer, dcStr As String
  3.  
  4.         x = Val(Text1.Text)
  5.         dc = InStr(x, ".")
  6.         If dc > 0 Then
  7.             dcStr = Left(Mid(Text1.Text, dc + 1) & "00", 2)
  8.         End If
  9.         s = s & dcStr
  10.         If Len(s) > 2 Then
  11.             MsgBox dcStr & "-  More Decimals"
  12.             s = ""
  13.         End If
  14.  
But I am getting problem when entering more than 2 decimals or if I backspace the digits.
Please Help me.
ThanQ!
Nov 22 '07 #2
kadghar
1,295 Expert 1GB
Also can I restrict to enter only 2 decimal places?
I tried this code in TEXT_CHANGE()

But I am getting problem when entering more than 2 decimals or if I backspace the digits.
Please Help me.
ThanQ!
you can use doubles and singles instead of strings for this very problem

Expand|Select|Wrap|Line Numbers
  1. dim dou1 as double
  2. dim sin1 as single
  3. dou1=abs(text1.text)
  4. sin1=dou1 - int(dou1)
Depending on the version, you might or might not have ABS, if you dont, just create it

Expand|Select|Wrap|Line Numbers
  1. public function abs( a as double) as double
  2.     if a < 0 then a = a * -1
  3.     abs = a
  4. end function
If you want SIN1 as an integer, well, there are many ways:

Expand|Select|Wrap|Line Numbers
  1. while int(sin1) <> sin1 
  2.      sin1=sin1*10
  3. wend
or instead of doing that, to restrict it to N decimals just;

Expand|Select|Wrap|Line Numbers
  1. sin1 = sin1 * 10^n
HTH
Nov 22 '07 #3
Mohan Krishna
115 100+
you can use doubles and singles instead of strings for this very problem
:
:
THANK YOU VERY VERY MUCH!

But how to restrict i could not get it!

ThanQ Once Again!
Nov 22 '07 #4
Mohan Krishna
115 100+
Hi Khadgar!

I changed the code as
Expand|Select|Wrap|Line Numbers
  1.     Dim dou1 As Double
  2.     Dim sin1 As Single
  3.     Dim n As Integer
  4.     dou1 = Abs(Text1.Text)
  5.     sin1 = dou1 - Int(dou1)
  6.  
  7. '    While Int(sin1) <> sin1
  8. '     sin1 = sin1 * 10
  9. 'Wend
  10.  
  11.     n = 2
  12.     sin1 = Round(sin1, n) * 10 ^ n
  13.  
  14.     Text2.Text = sin1
  15.  
ThaQ for an idea!
Nov 22 '07 #5
kadghar
1,295 Expert 1GB
Hi Khadgar!

I changed the code as
...
ThaQ for an idea!
yeap, that's right, the first method is to keep all decimals, the second to restrict them, you shouldnt use both, or you'll get all the decimals plus N zeros.
Nov 22 '07 #6
Mohan Krishna
115 100+
yeap, that's right, the first method is to keep all decimals, the second to restrict them, you shouldnt use both, or you'll get all the decimals plus N zeros.
Yeah!
I did the same. Thank You!
Nov 23 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: Batista, Facundo | last post by:
Here I send it. Suggestions and all kinds of recomendations are more than welcomed. If it all goes ok, it'll be a PEP when I finish writing/modifying the code. Thank you. .. Facundo
6
by: Peter Blatt | last post by:
Does 5 represent the total numer of digits (including the fractional portion) or only the number of places BEFORE the decimal point? Moreover does the number include the decimal point? Are there...
3
by: Artek | last post by:
Hello, after installing .net 1.1, ASP.NET works fine, but there is a problems with extra zeros added to the numbers at the end. In Sql 2000 SP3a there is for example a table with one column ...
3
by: Amaryllis | last post by:
Hi again, I'm new to the world of communicating between VB.NET and AS/400, so I've been posting a lot of questions lately since no one else in the company has done anything like this before. ...
15
by: Kay Schluehr | last post by:
I wonder why this expression works: >>> decimal.Decimal("5.5")**1024 Decimal("1.353299876254915295189966576E+758") but this one causes an error 5.5**1024 Traceback (most recent call...
11
by: Pieter | last post by:
Hi, I'm having some troubles with my numeric-types in my VB.NET 2005 application, together with a SQL Server 2000. - I first used Single in my application, and Decimal in my database. But a...
4
by: =?Utf-8?B?UmljaA==?= | last post by:
Is there a way to determine if a numeric value contains a decimal? how to do this? If IsNumeric(txt1.Text) then ... so now I know that txt1.Text is a numeric value. How can I tell if it is a...
8
by: iDaz | last post by:
hi everyone! i've searched many sites including this one for the answer to me question, but i'm still in a bit of trouble. this is my current code... Private Sub unitPriceKeyPress(ByVal sender...
10
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places?...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.