Showing posts with label trailing. Show all posts
Showing posts with label trailing. Show all posts

Saturday, March 31, 2012

Trim trailing 0 from decimal place of number

Hi,

I am having difficulty trimming any traling 0's from my decimal numbers.
I store then in the database to 2 decimal places.
This means that when they come back to my application they still diply with
all the decimal places

eg

10.00 displays as 10.00
10.10 displays as 10.10

what I would like to achieve is the following

10.00 displays as 10
10.10 displays as 10.1

many thanks in advance

cheers

martin.string.Format("{0}",10);
string.Format("{0}",10.10);

should do the trick. Actually the above behavior should be the default
behavior...

+++ Rick --

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
-----------
Making waves on the Web

"martin" <Stuart_REMOVE_36@.yahoo.com> wrote in message
news:OXKXwadbEHA.2216@.TK2MSFTNGP10.phx.gbl...
> Hi,
> I am having difficulty trimming any traling 0's from my decimal numbers.
> I store then in the database to 2 decimal places.
> This means that when they come back to my application they still diply
with
> all the decimal places
> eg
> 10.00 displays as 10.00
> 10.10 displays as 10.10
> what I would like to achieve is the following
> 10.00 displays as 10
> 10.10 displays as 10.1
> many thanks in advance
> cheers
> martin.

Trim trailing 0 from decimal place of number

Hi,
I am having difficulty trimming any traling 0's from my decimal numbers.
I store then in the database to 2 decimal places.
This means that when they come back to my application they still diply with
all the decimal places
eg
10.00 displays as 10.00
10.10 displays as 10.10
what I would like to achieve is the following
10.00 displays as 10
10.10 displays as 10.1
many thanks in advance
cheers
martin.string.Format("{0}",10);
string.Format("{0}",10.10);
should do the trick. Actually the above behavior should be the default
behavior...
+++ Rick --
Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
--
Making waves on the Web
"martin" <Stuart_REMOVE_36@.yahoo.com> wrote in message
news:OXKXwadbEHA.2216@.TK2MSFTNGP10.phx.gbl...
> Hi,
> I am having difficulty trimming any traling 0's from my decimal numbers.
> I store then in the database to 2 decimal places.
> This means that when they come back to my application they still diply
with
> all the decimal places
> eg
> 10.00 displays as 10.00
> 10.10 displays as 10.10
> what I would like to achieve is the following
> 10.00 displays as 10
> 10.10 displays as 10.1
> many thanks in advance
> cheers
> martin.
>

Trim URL String

I am trying to populate selected values from a drop-down list into URL params. I have the below code, which is supposed to remove the trailing comma from the end of the URL, but it does not seem to be working. Does anyone see anything obviously incorrect?

Thanks in advance.
----------

if (lbxWFTemplate.Visible ==true)

{

strURL +="WFTemplate=";

foreach (ListItem liWFTemplatein lbxWFTemplate.Items)

{

if (liWFTemplate.Selected)

{

strURL += liWFTemplate.Value.ToString() +",";

}

}

strURL.TrimEnd(",".ToCharArray());

I actually figured this out right after I posted. Trimend() returns a string, so the following was changed, and the code works as expected now:
strURL = strURL.TrimEnd(",".ToCharArray());

Trim Trailing Comma in an Array

Hi - I thought this would be easy but I can't find an answer. I have an ArrayList seperated by commas and I want to trim off the last comma in the list. The VB function throws an error. Thanks

Dim myList As New ArrayList

'Does not work
myList.Trim()

Hi,

You need to explain your problem a little better.

Do you have an arraylist of strings and you want to trim off the last comma of each string in the arraylist ?

Roy.


I'm not sure if I understand what you are trying to do. How do you have an ArrayList seperated by commas? The point of an Array is that each item is accessible through an index, and it doesn't need a delimeter. If you want to remove an item from the array, you can use myList.Remove(object to remove) or myList.RemoveAt(index to remove). The Trim method is for strings.

Hi - I'm populating an arraylist from a datareader like below

Dim myList As New ArrayList
Dim dr As SqlDataReader
Dim count As Integer

strSQLConn = New SqlConnection(ConfigurationSettings.AppSettings("ConnString"))
strSqlText = "getIndustries"
cmd = New SqlCommand(strSqlText, strSQLConn)
cmd.CommandType = CommandType.StoredProcedure

Try
strSQLConn.Open()
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
With dr
If .HasRows Then
While .Read
myList.Add(.GetString(0))
myList.Add(",")
count += 1
End While
End If
End With

End result below. I need to remove that last comma at the end of Video Rentals.

Travel Services,Trucking & Shipping,Utilities Electric,Utilities Natural Gas,Utilities Water & Waste,Video Rentals,


Ok the easy answer is to use:

myList.RemoveAt(myList.Count - 1);

However I have to ask, why are you inserting commas after each value? And why are you using an arraylist? It seems to me that a string array would be more efficient. Also, what's the purpose of the "count" integer? You can use myList.Count to see how many objects are in the ArrayList (assuming you aren't inserting commas in between).


To take off the last comma in the last element of the Array, you could use something like

myList.Item(myList.Count - 1) = myList.Item(myList.Count - 1).ToString.Trim(",")

Depending on what you are doing with the array later, it may work better to leave the commas out of the array and just add them when you display the contents of the Array.

Otherwise, you could just build a string instread of an array.

Something like this:

Dim myList As New StringBuilder()While .Read myList.Append(.GetString(0)) myList.Append(",") count += 1End While

Heck, now that I think of it, you could be using a StringBuilder too, which is *much* more efficient with a large number of concatenations:
Dim myListAs New ArrayListDim drAs SqlDataReaderDim countAs Integer Dim mySBAs New StringBuilder() strSQLConn =New SqlConnection(ConfigurationSettings.AppSettings("ConnString")) strSqlText ="getIndustries" cmd =New SqlCommand(strSqlText, strSQLConn) cmd.CommandType = CommandType.StoredProcedureTry strSQLConn.Open() dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)With drIf dr.HasRowsThen While dr.Read mySB.Append(dr.GetString(0) + ",") count += 1End While End If End With

Then you could do something like this to trim it:

String myResult = mySB.ToString().TrimEnd(",".ToCharArray());
HTH

If your array is a string like

Dim sTest = "A,B,C,D,"

Then a test along the lines of

If sTest.EndsWith(",") Then sText = sTest.Substring(0, sText.Length - 1)

should do it.

(I am awaiting my copy of VS2005 as part of my MSDN subscription, so the above is unchecked as to syntax.)



hello ,

here is a little idea i dont know if this function is available in vb.net since i m a c# programmer

may be it help you ,

mylist.RemoveAt(mylist.LastIndexOf(

","));

Regards

Gurpreet


Thanks very much!

Trimming data in dropdownlist from sqldatareader

When I databind a value/text combination from an
sqldatareader to a dropdownlist, the trailing spaces are
getting included in the dropdownlist. I can RTRIM from
within the SQL to fix this problem, but I am wondering if
there is a more elegant solution to trim all the
text/value combinations in a dropdownlist.Hi William

To my knowledge, there is not an elegant way from dropdownlist side. One
clumsy way I can think of is to populate a new collection or arraylist that
contains the data fields to be bound to the dropwodnlist. While populating
this new collection or arraylist we can trim the data accordingly.

Please let me know if it makes sense.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
Yes, that makes sense. Thank you.
>--Original Message--
>Hi William
>To my knowledge, there is not an elegant way from
dropdownlist side. One
>clumsy way I can think of is to populate a new
collection or arraylist that
>contains the data fields to be bound to the
dropwodnlist. While populating
>this new collection or arraylist we can trim the data
accordingly.
>Please let me know if it makes sense.
>Best regards,
>Jacob Yang
>Microsoft Online Partner Support
>Get Secure! C www.microsoft.com/security
>This posting is provided "as is" with no warranties and
confers no rights.
>.