Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

decimal places in form

Status
Not open for further replies.

vbcad

Technical User
Jul 12, 2002
159
0
0
US
How do i format the decimal places in a text box in a visual basic form to display correctly? The help files are not very clear.
 
Here are some examples. Is this what you are looking for?

Textbox.Text = Format(5459.4, "##,##0.00") ' Returns "5,459.40".
TextBox.Text = Format(334.9, "###0.00") ' Returns "334.90".
 
Hi,

You can also the use Round to display the desired number of decimal places..

ie:

Code:
Dim MyNumber As Double
Dim Decimal_Places As Integer

MyNumber = 2

My Number = Round(MyNumber, decimal_places)

...or simply

Code:
My Number = Round(MyNumber, 2)

Note!: Omitting the number of decimal places, rounds the number up or down to the next nearest whole number:

ie:
Code:
My Number = Round(MyNumber)


I hope this helps..

Cheers,

Renegade.. BULLET-PROOF DESiGNZ
renegade@tiscali.co.uk
 
I think this will help. The number in the text box is a calculated value returned from an excel sheet in a application i am using. will this work on a number that is different all the time? Or does the number have to be an established constant number in the text box?
 
Hi,

Yeah, It should do. As long as the number is passed to the variable (MyNumber, or whatever you called it)..

Mind you, you can pass a whole bunch of numbers to as many variables as you like - so long as you pass the variables through the round function (individiually) they will always have they desired number of decimal places. the syntax is the same for all as in the my previous reply..

I hope this helps,

Cheers,

Renegade.. BULLET-PROOF DESiGNZ
renegade@tiscali.co.uk
 
thanks works great now. i had to set the reference to this format. textbox.Text = Format(xlsheet.Cells(15, 1), "###0.0"). thanks for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top