Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  HOME    TRACKER    Visual Basic

Help Me.. Textbox That Wud Accept Numbers Up To 2 Decimal Places

i have a problem..

I was asked to, create a textbox, (txtUnitPrice), that would allow input of Numbers only,
*accept numbers only
*up to 2 decimal places
    once the decimal(.) was pressed, only 2 numbers are allowed,
*no repetition of (.) decimal

for example
 2,896.75 or

once i input Price on the textbox, i wont be allowed to pressed (.)decimal twice

Please help me. i really dont know what to do..
I know how to use the keyascii for Numeric input only..

i just really dont know, how can i set .00 2 decimals only

My teacher suggest that i may use

instr(txtUnitPrice,".") i dont know whats next

should i use counter..?? pls help me..
i would really appreciate... pls

View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Text Box To Accept Numbers And Decimal
How do I get a textbox to accept numbers and decimal only? ex. 1.5,1.75, etc.?

Displaying Whole Numbers With 2 Decimal Places (ie 100.00)

Im trying to display results from sums with 2 decimal places.

When i get a whole number or a number with a decimal point ending with a 0 or two 0's it cuts off the 0 alltogether.

Ie. (100 will display as 100 not 100.00 or 105.30 will display as 105.3)

I need the full decimal values as Im trying to display currency figures.

for example of i do text1.text = (480 * 0.175) i get an answer of 84. and not 84.00.

also storing values into variables i have the same problem. the output of that variable is cut off.

Im sure theres a simple answer if anyone could help me!


Divide Two Numbers Upto 5000 Decimal Places??

I want to know how to divide two numbers upto 5000 decimal places like it was done in a previous post on this forum pls..

"Calculate 13155187 / 13417 with 5000 decimals.
The solution is the last 6 numbers (of those 5000 decimals)."

the link is here:

thx a ton!

2 Decimal Places In Textbox
I have got 2 textboxes. The summation of the numbers in the 2 textboxes should go in third textbox. I am doing it in the following way:
text3.text = cdbl(text1.text)+cdbl(text2.text).

What I want is the number in third text box should not exceed 2 decimal places. How to do it??? Help!!!!

Textbox Decimal Places
Hi, I am trying to display a number in a textbox but it is returning too many decimal places. How do I set the number of decimal places the textbox will display?

I have already tried setting the DataFormat of the textbox to number and setting the decimal places but it does not work.

Thanks in advance

Textbox That Accept Only The Numbers
how can i make the textbox accept only the numbers inputed from the user!!!!!

TextBox To Accept Numbers Only
I am looking for a TextBox to accept numbers only.
The entries into the TextBox should be RighttoLeft.
I should be able to define the number of integers and decimals req.

How To Set Textbox Property To Accept Numbers Only?

I am new to VB. I am trying to set a property of a textbox so it accepts only numbers which have to be exactly 10 digits long (not less, not more).

Could you plese help me resolve this issue?

Thank you in advance


How To Make A TextBox Only Accept Numbers?
Hello eveybody:

Someone know how to change this code below to only accept numbers?

PS: The code below only accept letters.


If KeyAscii >= vbKey64 And KeyAscii <= vbkey122 Then
KeyAscii = 0
End If


Thanks a Lot.

How To Validate Textbox Such That It Will Accept Only Numbers
How to Validate Textbox such that it will accept only Numbers
How to Validate Textbox such that it will accept only Text not Numbers

any Function

Textbox Should Onluy Accept Numbers
I have 4 textboxes(an array). The first one accepts characters and the others only numbers. I want my program to raise an error if characters are entered in the Numeric fields. I know how to do it when the textboxes are not in an array,

Rounding Numbers To 2 Decimal Places - How To ? (Rounding)
I am returning math to a variable (and/or a text box) BUT I only want to have two or three decimal places, that are rounded off.

I cant figure out how to round them. I've tried setting text box properties, calling 'as currency' but I dont know what else to do.

Thank you.

2 Decimal Places Or Not 2 Decimal Places.
Is it possible to format a column of numbers to 2 decimal places but if the decimal places are 0's then to only show a whole number.

so 2.22 shows as 2.22

but 2.00 shows as 2

I don't necessarily want the solution just a nudge in the right direction.

Decimal Places
I have a sheet of inputs for users. The idea is that they should input to a specific number of decimal places. I was wondering if I can set up something that restricts them to only enter, say for e.g. 2 d.p. I was thinking along the lines of a simple if function - but didnt know how to set it up.

Does anyone have the best solution to this problem?

Decimal Places
How do I limit the amount of decimal places for a returned amount for instance...

iValue = 800/ 31

will give you 25.8064516129......

How could I limit it to two decimal places?

I Need More Decimal Places

Does anyone know how to get a lot of decimal places in vb6.

For example, if I do a calculation, it will give me something like

4.2348974924324 E+8

but I need many more decimal places, at least 50!

Thanks in advance

Decimal Places
hello, using MS Excel, cell A1 has the value of 10

I have a userform with a label called Label1

What i need to do is this

The number in A1 (10) has to appear in Label1... BUT

the number that appears in the label must always appear to 2 decimal places.

For Example

10 would appear as 10.00
15.7 would appear as 15.70
14.96 would appear as 14.96
10.582 would appear as 10.58

How can i get a code to make force the number to always appear as 2 decimal places.?

Thanks for help, Nay

Decimal Places?
I have...

Dim Number(1 to 5) as Long

Number(1) = 2.0
Number(2) = 2.2
Number(3) = 2.4
Number(4) = 2.6
Number(5) = 2.8

TextBox1.Text = CStr(Number(1))
TextBox2.Text = CStr(Number(2))
TextBox3.Text = CStr(Number(3))
TextBox4.Text = CStr(Number(4))
TextBox5.Text = CStr(Number(5))

But I get "2", "2", "2", "3" and "3" in the text boxes. How do I maintain the decimal places. Also in general how do I specify the number of decimal places I require. ie. If I wanted to display "3.46" or "7.85763". Thanks.

2 Decimal Places
Can someone tell me how to format a price to "2 decimal places". I'm using sequential files and when working out totals, I get answers like 33.6789 instead of 33.67
Any Help, much appreciated !

Decimal Places
I have the following code,

Private Sub cmdCalculate_Click()
Dim totalprofit As Single

totalprofit = txtSupPrice * txtProfit / 100
txtCustPrice = txtSupPrice + totalprofit
It works well
But the answer is to about a million decimal places
How do i put this to just two?


Decimal Places
please can someone help

i have declared something as a single and wnt to display it in a textbox to just 2 decimal places.

anybody any ideas on how to cut it down to 2dp

thanx in advance

Decimal Places
Is there a way of getting a text box to display the result of a multiplication in the format 00.00 always?

I can get it in this format when the numbers being multiplied are fractions, but whole numbers generate an answer with no decimal places. can anyone help?

Decimal Places
If the user types 1200 into a text box I would like it to automatically change to 1200.00 and if the user types 1200.00 it will also accept it as 1200.00

Ideas please, got a bit stuck on this I am afraid.

Thanking you in advance.

Decimal Places
This is gonna be my final question on my Database for Collage. So i would like to thank everyone on this forum for all the help.

How can i make a number format to 2dp.

Decimal Places
How can i make it so that a integer has 2 decimal places?


Dim p As Integer

P = 1

Label1.caption = P

Then the label would show 1

How can i make it show 1.00?

Set Decimal Places
What's the code to set decimal place to 2?

"CREATE TABLE tmpTable " & _
"(SumTest double)"

Why No 2 Decimal Places?
i have set the variables used as curency

i have set the text box format as curency.

so why when i perform calculations and place the results in the relevent text boxes does the numbers have about 8 decimal places?

Decimal Places
I'm new with this and I have a project to do in my programming class - I have to compute an average grade, accurate to 2 decimal places...without dropping the zeroes, if it works out that way. My program is set up with 6 text boxes to input different numbers in, each of which is multiplied by a decimal...then all of those values are added up and the value is supposed to be printed to a picturebox (which I did). How do I format the number in the picturebox to be accurate to 2 decimal places every time?

Decimal Places
If the user types 1200 into a text box I would like it to automatically change to 1200.00 and if the user types 1200.00 it will also accept it as 1200.00

Ideas please, got a bit stuck on this I am afraid.

Thanking you in advance.

Decimal Places
How do I make VB limit the answer to a math question to two decimal places?

12.35543345 becomes 12.35

or round the number down to 12.36

Decimal Places
I have a question. I have the following code.....

Public DistanceProfile(64000) As Single

Text1 = DistanceProfile(nIndex) 'nindex changes with a timer

How do I limit the Text1 to only display two decimal points?



&gt;10 Decimal Places?
Is there any way to return a value (ie. (Atn(1/3)) to a whole heck of a lot of decimal places? Thanx.

2 Decimal Places
Thanks for the reply Chris but i still can't get it to work.

This is what I am trying to do.
One text box has a decimal numer with unlimited decimal places.
the other has a whole number and when i tab out of the box with the whole number it multiplies one by the other and displays the result in a seperate text box. i want the result to be 2 decimal places long in the result text box as i am dealing with currency,
I would be grateful for any Help

2 Decimal Places
Just 1 more question!!
How do i format a text box to display a number as two decimal places even if the number is input like this ##.##########

Decimal Places
My final calculation shows the amount as 245.08767

is there a way to round the figure to 2 decimal places.

ie i want the answer to display 245.09

also is there a way to put the $ symbol in front of this 2 decimal place figure as this is the final result and i dont need to do anymore calculations with the figure

15 Decimal Places
I need to have a variable hold 15 decimal places. I cannot seem to get it to work.

The users enter $ values in text boxes, the software then takes those numbers and converts then to other values. How can I get a variable to hold a 15 decimal place value.

thank you for any assistance.


Set A Value As A Decimal To Two Places
Hi All,

I am passing a value two and from an access database after a calculation. How do I set a varable to two decimal places?



Decimal Places!
Ok, this is really, really annoying me.

I have an assignment which I have completed (I am not asking you to write it for me! I HAVE done it), which is a currency converter.

It uses two combo boxes, and converts one currency to the next, and posts the results in a text box. However, the results are strange - If I have one Aus dollar, and I convert it to Euros, the conversion rate is something like 0.56, and I have said for it to be multiplied by that much.. However, the number it returns is something along the lines of "0.56000007565" or some such number... I have tried everything to set it to two decimal places - Using the properties menu and such like... Nothing works! It is really frustrating me..

Thank you for your help.

Decimal Places
this there a function to return only two decimal places for a number or a code as to be written.
if code please help.

Decimal Places
Hi gurus
I have few text boxes to have currency value. I set the data format to currency with two decimal places. When I multiply or divide few value of the text box, I am getting more than 2 decimal places. How do I control the entire field to be in 2 decimal places?

Thank you,
Kethees s.

Decimal Places Without E-2
I ran into this problem one other time but can not remember what I did to fix it. Its a simply thing.
I have an app that divides one number by another, for example 13/150. The correct answer should be .08667. For some reason the app returns the value 8.6666666E-2 or something similar. How can I get the correct value returned. I only need 2 decimal places.
Todd Poole

Why My Ado Can Not Accept Decimal Number
I've this code:
my ado can not show decimal even it is assigned by decimal number???

adoProd.Open "select * from Products", cnn, adOpenDynamic, adLockOptimistic


adoProd.Fields("Qty").Value = Val(txtQty.Text)
' my txtQty has value 2.5 but my adoProd keep giving me 2 (not 2.5), even though I give different format of my txtQty with:
' * FormatNumber(Val(txtQty.Text), 2)
' * Format(txtQty.Text, "#,##0.00")

Problem With Decimal Places
Hi there,

I am converting time into decimal such as 60 seconds = 1. 30 seconds = 0.5 etc.

My code is as follows:

Dim dec As Single
Dim dec1 As Single

dec = Format(ComboBox1.Value / 60, "###0.00")
dec1 = Format(ComboBox2.Value / 60, "###0.00")

Where comboBox1 and 2 hold the following 0,10,20,30,40,50,60.

However, when these figures go into excel they are formatted to 2.d.p but the actual number is not formatted.

such as if comboBox1 = 10 then the answer is 0.17. However, in the tool bar the answer is actually 0.170000001788139?

How do I round these to 2 decimall places?

Maths And Decimal Places
I am puzzled by this.

My data consists of numbers that increment or decrement by 0.05 precisely. I perform a very basic addition of these numbers. You would think the result would be a number that is a multiple of 0.05 and only 2 decimal places. There is NO problem when the numbers increment by 0.25.

Why do I get a result like 2.649948 for profitbuy??

here is some of my code:

tradebuyprofit(x) = tradeclose(x) - buystop(x)
sellimit(x) = tradeclose(x)
sellimitime(x) = closetime(x)

c = c + 1 'trade counts
profitbuy = profitbuy + tradebuyprofit(x) 'profit
profitsell = profitsell + tradesellprofit(x)

c = c + 1 'trade counts
profitbuy = profitbuy + tradebuyprofit(x) 'profit
profitsell = profitsell + tradesellprofit(x)

Form1.Print "Number of Trades="; c, profitsell, profitbuy
Form1.Print "Trades="; c, "Profit/Loss="; profitsell + profitbuy, "Average="; Round(((profitsell + profitbuy) / c), 2)

No More Than 2 Decimal Places In An Answer...
Ok I've gotten all math to work, how do I restrict the answer to 2 decimal places? Her is my code, and it works fine, it just wants to show infinite decimal places.

Private Sub txtDays_Change()
lblResult2.Caption = CStr(Val(lblResult1.Text) / Val(txtDays.Text))
End Sub

Decimal Places && Variables
I am having trouble moving the decimal place in my variables. I want the number that I display to read "1.2" but it shows up as "1". my code is posted below.

Dim PL as Double

PL = (ProfLoss * 10) 2

any help in this area would be much appreciated!


Round Down Decimal Places
Hi there,

i would like to ask if there is VB function that can round down to any decimal places. For example,
12.56->12.5 (round down to one decimal)
345.5463->345.54 (round down to two decimals)


Limiting Decimal Places

I want the caption of Label to be the result of a calculation of two variables. (Eg. 4 / 6).

At the moment, it is coming out into several decimal places (0.6666666667). How do i limit the answer to just one decimal place(0.7)?

I would be grateful for your help, Cheers!

How To Get A Label To 2 Decimal Places
i have a label at the bottom of my page which adds up the total of some things and adds VAT on but sometimes it comes out as 32.343 rather than 32.34 any ideas?


Copyright 2005-08, All rights reserved