Link to home
Start Free TrialLog in
Avatar of Seven price
Seven priceFlag for United States of America

asked on

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

Avatar of Glenn_Moore
Glenn_Moore

Change your format "xx.oo" to "xx.x"
Avatar of Seven price

ASKER

are you talking abou this

 prm.Value = String.Format(Me.Price.Text, "##.00")
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.
maybe this will help clarify similar to this problem

https://www.experts-exchange.com/questions/21038093/Using-Format-function.html
ASKER CERTIFIED SOLUTION
Avatar of Glenn_Moore
Glenn_Moore

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ok i am a newbie at this and I have no idea what ou wrote here
What is your specific application?
windows, asp.net visual basic, windows forms, visual studio 2003, 1.1 frameworks
prm.Value = String.Format(Me.Price.Text, "##.0")
it displays but with out the decimal, for example if i put 33 it will come up 33 not 33.0 but now errors.
no errors excuse the english
By using the .00 you are asking for two decimal places.  What happens if you do "xx.x" instead?
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

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

I am not sure what you are saying?  Please give an example.
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
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>
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
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