• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 196
  • Last Modified:

Format in vb

Yes i am trying to use format where once i add a numeric number for example.
3 when i add 3 in my form it will got to my datagrid and display 3.0

but if a user adds 3.0 it will just display 3.0


prm = New SqlParameter("@Price", SqlDbType.Decimal)
        prm.Direction = ParameterDirection.Input
        prm.Value = String.Format(Me.Price.Text, "##.00")
        'Me.Price.Text = Decimal.Round(Me.Price.Text, 0.0).ToString()
        cmd.Parameters.Add(prm)

Open in new window

0
Seven price
Asked:
Seven price
  • 13
  • 6
1 Solution
 
Glenn_MooreCommented:
Change your format "xx.oo" to "xx.x"
0
 
Seven priceFull StackAuthor Commented:
are you talking abou this

 prm.Value = String.Format(Me.Price.Text, "##.00")
0
 
Seven priceFull StackAuthor Commented:
well i change  prm.Value = String.Format(Me.Price.Text, "##.00") to

 prm.Value = String.Format(Me.Price.Text, "00.0")

but i only get the value if i put  prm.Value = String.Format("0.00") but that would only display the value of 0

I even tried Convert.ToDecimal nothing is working. anything else then i can get out of your hair.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Seven priceFull StackAuthor Commented:
maybe this will help clarify similar to this problem

http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_21038093.html
0
 
Glenn_MooreCommented:
What about:
Function FormatNumber(Expression, [NumDigitsAfterDecimal As Long = -1], [IncludeLeadingDigit As VbTriState = vbUseDefault], [UseParensForNegativeNumbers As VbTriState = vbUseDefault], [GroupDigits As VbTriState = vbUseDefault]) As String
0
 
Seven priceFull StackAuthor Commented:
ok i am a newbie at this and I have no idea what ou wrote here
0
 
Glenn_MooreCommented:
What is your specific application?
0
 
Seven priceFull StackAuthor Commented:
windows, asp.net visual basic, windows forms, visual studio 2003, 1.1 frameworks
0
 
Glenn_MooreCommented:
prm.Value = String.Format(Me.Price.Text, "##.0")
0
 
Seven priceFull StackAuthor Commented:
it displays but with out the decimal, for example if i put 33 it will come up 33 not 33.0 but now errors.
0
 
Seven priceFull StackAuthor Commented:
no errors excuse the english
0
 
Glenn_MooreCommented:
By using the .00 you are asking for two decimal places.  What happens if you do "xx.x" instead?
0
 
Seven priceFull StackAuthor Commented:
I understand the # as a place holder and i tried it but it gives me the value i put inside the text box but thats it.


 prm = New SqlParameter("@Price", SqlDbType.Decimal)
        prm.Direction = ParameterDirection.Input
        prm.Value = String.Format(Me.Price.Text, "xx.x")
        cmd.Parameters.Add(prm)

Open in new window

0
 
Seven priceFull StackAuthor Commented:
i tried all thes formats also still returns 3 instead of 3.0 or 3.00
prm = New SqlParameter("@Price", SqlDbType.Decimal)
        prm.Direction = ParameterDirection.Input
        'prm.Value = String.Format(Me.Price.Text, "xx.x")
        'prm.Value = String.Format(Left(Me.Price.Text, "##.00"))
        prm.Value = String.Format("{0:D}", Me.Price.Text)
        'Format(Left(Me.Price.Text, 4), "##.00"
        'prm.Value = Format(me.Price.text, "00.0")
        'Me.Price.Text = Decimal.Round(Me.Price.Text, 0.0).ToString()

Open in new window

0
 
Glenn_MooreCommented:
I am not sure what you are saying?  Please give an example.
0
 
Seven priceFull StackAuthor Commented:
if you see in the iimage the price is just 3 but in the other image its 1.89 because i added 1.89 but i need the 3 to be 3.0 when added
ScreenHunter-01-Jan.-29-12.28.gif
0
 
Seven priceFull StackAuthor Commented:
ok so the add parameter is not going to work because this is adding what i am thinking we have to style this when it is bounded already within the datagrid. So on the front end within the datagrid we have to change the format within the datagrid when the information is there already. what you think.

<asp:/BoundColumn DataField="price" >
</bound>
0
 
Seven priceFull StackAuthor Commented:
Ok to do this I found out such a easier way.

On the Datagird and the tables you have to the Templatecolmn

use the boundcolumn DataFormatString="{0:N}" or any formatt you like to display .

Thanks for trying
0
 
Seven priceFull StackAuthor Commented:
Ok to do this I found out such a easier way.

On the Datagird and the tables you have to the Templatecolmn

use the boundcolumn DataFormatString="{0:N}" or any formatt you like to display .

Thanks for trying
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 13
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now