[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
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)
Re: [2005] Display only 1 decimal place of an Int or Double
even easier...
VB Code:
Textbox1.Text = dl.ToString("#.#")
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.
Re: [2005] Display only 1 decimal place of an Int or Double
Quote:
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.