|
-
Feb 17th, 2007, 06:38 AM
#1
Thread Starter
Member
[RESOLVED] [2005] Display only 1 decimal place of an Int or Double
Hi all, this should be an easy one:
How can you show only one decimal place of a Double, not lose the remaining accuracy just only show (eg in a text box) 1dp.
Dim number as Double = 1.2345
textbox1.text = "<here i want to only show 1.2>"
thanks all
-
Feb 17th, 2007, 06:58 AM
#2
Hyperactive Member
Re: [2005] Display only 1 decimal place of an Int or Double
Here's one way....
VB Code:
Dim dl As Double
dl = 1.2345
TextBox1.Text = dl.ToString.Substring(0, dl.ToString.IndexOf(".") + 2)
If my post helps , please feel free to rate it 
-
Feb 17th, 2007, 07:20 AM
#3
Lively Member
Re: [2005] Display only 1 decimal place of an Int or Double
even easier...
VB Code:
Textbox1.Text = dl.ToString("#.#")
-
Feb 17th, 2007, 09:22 AM
#4
Re: [RESOLVED] [2005] Display only 1 decimal place of an Int or Double
Just for further info, you should check out the Round function in the System.Math class.
-
Feb 17th, 2007, 07:57 PM
#5
Re: [2005] Display only 1 decimal place of an Int or Double
 Originally Posted by jamesclarke112
even easier...
VB Code:
Textbox1.Text = dl.ToString("#.#")
I would suggest using standard numeric format strings in preference to custom numeric format strings wherever possible. That way you ensure that you use the current systems chosen formats. To display a number with a single decimal place would be:You can find all the possibilities, both standard and custom, simply by searching MSDN for format strings. You'll find information for numbers and dates/times.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|