Formatting Numeric Values

Tyecom

Well-known member
Joined
Aug 8, 2007
Messages
78
Programming Experience
Beginner
I have several textboxes that has numeric values. But the values are coming back like this:

1245.0000
1674.0000
7819.0000

I can't get rid of the 4 zeros at the end. I want the numbers to come over as whole numbers.

My Code:

PPTotal.Text = Convert.ToDecimal(dr(16)).ToString("#.00")
FixTotal.Text = Convert.ToDecimal(dr(17)).ToString("#.00")
TotalValue.Text = "$ " + Convert.ToDecimal(dr(16) + dr(17)).ToString("#.00")

Any Suggestions? Thanks in advance.
 
using the following format:

Format(<expression>, <style>)

example:

Dim dbl as double = 1234.0000

Format(dbl,"0")

dbl = the double value
"0" = indicates how many decimal places i.e. if 0.0 the result will show 1234.0

Obviously if the decimal value is 1234.12 - you should decide if it needs to be rounded up or down

Hope that helps ;)
 
This doesn't work. The textbox I am trying to format is a calculation. Therefore, anyone total in the textbox needs to be formatted. Please refer to code in first post. Thanks in advance.
 
add a textbox to enter the number and a button and try the following code
VB.NET:
 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim str As String
        str = TextBox1.Text
        MessageBox.Show(FormatNumber(str, 0))
End Sub

please not that i assumend that all the number are in the format of ###.00000..... - (only zeros as decimal places)
the example eliminates the zeros

hope that helps ;)
 
Back
Top