plz Help: Converting 4 decimal places to 1 decimal place

I would like to convert 4decimal places to single(1) decimal place.
For that i wrote below code. Its working sometimes.

Input: StrAnlPct = "3.0000,2.9833,3.6546,4.65+6,5.54986,81.dsfds"
Output: "3.0,2.9,3.6,4.6,5.5,81.d"
For first example its working,
Input: StrAnlPct = "476290.4762,120.0000"
For this i m getting error. Error is:
    "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: startIndex "
   Source Error: At Line 590
Line 588:                    posanlpct = 1
Line 589:                    Do While posanlpct > 0
Line 590:                        If strAnlPct.IndexOf(",", posanlpct) > 0 Or strAnlPct.IndexOf(".", 0) Then
Line 591:                            posanlpct = strAnlPct.IndexOf(",", posanlpct)
Line 592:                            If posanlpct > 0 Then
And The Code is:
                'StrAnlPct = "3.0000,2.9833,3.6546,4.65+6,5.54986,81.dsfds"
                If Not IsDBNull(strAnlPct) Then
                    posanlpct = 1
                    Do While posanlpct > 0
                        If strAnlPct.IndexOf(",", posanlpct) > 0 Or strAnlPct.IndexOf(".", 0) Then
                            posanlpct = strAnlPct.IndexOf(",", posanlpct)
                            If posanlpct > 0 Then
                                stranlpct2 = strAnlPct.Substring(0, posanlpct)
                                strAnlPct = strAnlPct.Substring(posanlpct + 1)
                                stranlpct2 = Mid(stranlpct2, 1, InStr(1, stranlpct2, ".") + 1)
                                stranlpct2 = Mid(strAnlPct, 1, InStr(1, strAnlPct, ".") + 1)
                            End If
                            stranlpct3 = stranlpct3 & "," & stranlpct2
                        End If

                    If stranlpct3.Length > 0 And stranlpct3.Substring(0, 1) = "," Then
                        stranlpct3 = stranlpct3.Substring(1)
                    End If
                End If

For first value it is coverting 476290.4, coming to second value it is giving error.
Can u plese help me in this issue.
Thanks for Advance.

7/7/2005 9:52:55 AM 91979 articles. 3 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 39

that's some crazy code. all you need to do is this:

Dim dToManyPlaces As Double = Double.Parse("123456.54321")
Dim dJustRight As Double = Math.Round(dToManyPlaces, 1)

Response.Write(dToManyPlaces.ToString() + ";" + dJustRight.ToString())

cheers :: thomas
7/7/2005 1:50:25 PM
If you're using SQL Server to initially retrieve the value you can use the STR function to perform your decimal rounding..

Select STR(123456.564321,20,1)

will return 123456.6

Good Luck

7/7/2005 5:21:38 PM

Similar Artilces:

problem with CAST and CONVERT in SQL Server2000 converting decimal places from 4 to 2
All of my currency columns are only storing 2 decimal places when I insert into the database but when I pull out the data with a SELECT statement, I always get 4 decimal places instead of the 2 that were inserted.  For example:  Database Price            SELECT statement Price 100.56                           100.5600 I have tried to use the CAST and/or CONVERT commands but I cannot g...

superreview granted: [Bug 314098] getProvider().toString() returns "Mozilla-JSS version 3.3" in JSS 4.x : [Attachment 202579] rounding of double(4) + double(1)/10 to two decimal places gives 4.21
glen beasley <> has granted Sandeep Konchady <Sandeep.Konchady@Sun.COM>'s request for superreview: Bug 314098: getProvider().toString() returns "Mozilla-JSS version 3.3" in JSS 4.x Attachment 202579: rounding of double(4) + double(1)/10 to two decimal places gives 4.21 ...

superreview requested: [Bug 314098] getProvider().toString() returns "Mozilla-JSS version 3.3" in JSS 4.x : [Attachment 202579] rounding of double(4) + double(1)/10 to two decimal places gives 4.21
Sandeep Konchady <Sandeep.Konchady@Sun.COM> has asked glen beasley <> for superreview: Bug 314098: getProvider().toString() returns "Mozilla-JSS version 3.3" in JSS 4.x Attachment 202579: rounding of double(4) + double(1)/10 to two decimal places gives 4.21 ------- Additional Comments from Sandeep Konchady <Sandeep.Konchady@Sun.COM> rounding of double(4) + double(1)/10 to two decimal places gives 4.21 instead of ...

convert varchar to decimal and display coln to 3 decimal places in gridview
  Hi  1. In SQL2005, i hv a 'table1' that has a field called 'Col1' of varchar type Now in a procedure, I declare variable '@Col2' of decimal(8,4) type,then fetch value of col1 into col1a(this is of varchar type) like: select @col1a=col1 from table1 where condition.  now i want to put value of @col1a into @col2, so I write: set @col2=cast(@col1a as decimal(8,2)) but its not wrkng,it gvs error:  unable to convert varchar to numeric data type. what is the problem????? 2.  I want to display field in gridview to 3 decimal places...

Want regex for decimal upto 4 places on right and 15 places on left.
Hi all,          I am using textbox for displying decimal number.I want apply following proper validation to it 1) It should be between 0 to 100. 2) It should allow only 4 decimal places and 15 digits to left of decimal point. 3) Should not accept char values. 4) All these should happen while use is entering the value in text box(i.e key press event). Kindly provide regex or javascrit for it. Thanks in advance.  SuyogI am just using my free time,but if it helps you then my mark my post as answer  use this:^0?(100|0?\d\d|0?0?...

How to round off the decimal value to 4 places in VB.NET
Iam getting the result ddlintresult as some 12.344444444444444444444  Dim ddlintresult As Decimal = Convert.ToDecimal(ddlint / lval)  How can i round off the values as 12.3445 Any suggestions or solutions are appreciated    Fred--Thats what my buddies call me Mark this as Answer, if this reply answers your post Math.Round has overloads to do exactly this.   Thanks ShadosFred--Thats what my buddies call me Mark this as Answer, if this reply answers your post...

decimal to varchar loosign decimal places
i convert 45.7895 using code below  CONVERT(varchar(10), TaxRate, 4) + '%' and the output is45.78%why the hell its cutting the 95 from the end? your business needs to build an online store.------------------------------First Click DAL 3.5/sql server/svn hosting Don't know for sure, but maybe it's because of the ,4.  Try ,10 as a test.C# <---> VB.Net Translator  Without knowing the datatyp...

Formatting a decimal to 2 decimal places
Hi - just testing some code, and the code below returns a number with 3 decimal places (eg. 450.000). Will returning a decimal always give 3 decimal places, and if so, how can I remove the last one? I don't want to use: Return String.Format("{0:C}", decRunningTotal) - as that will automatically add a $ or £ or whatever to the start, and I'd like to control that. I'd really appreciate any help, thanks, Mark Function GetItemTotal() As String objDT = Session("Cart") Dim intCounter As Integer Dim decRunningTotal As Deci...

Convert to two decimal places
Hi, Please help,  How can I convert the Tax in the following code which is Double to a two decimal place figure Public Shared Function GetBuyNowButton(ByVal itemName As String, ByVal itemNumber As String, ByVal price As Double, ByVal tax As Double, ByVal shipping As Double, ByVal userName As String) As String Please hel I have tryied everything I knew, am also new to VB. Thanks You can use Math.Round. Math.Round(value, 2)Ryan OlshanASPInsider | Microsoft MVP, ASP.NEThttp://ryanolshan.comHow to ask a question Thanks for replying Ryan, See I am learning VB and tryied the Math...

How to get 2 decimal places?
I have one session var and value of it will be double.How can i do it to be in 2 decimal places rounded up to nearest 5cents. eg.21.781 -> 21.10 21.322 -> 21.05 45 -> 45.00 Math.Round Method (Decimal, Int32, MidpointRounding)   Rounds a decimal value to a specified precision. A parameter specifies how to round the value if it is midway between two other numbers. Namespace: System Parameters d A decimal number to be rounded. decimals The number of significant decimal places (precision) in the return value. mode Specification for how to round d...

Convert variable to only two decimal places
Dim subtot As Double Dim tax As Double Dim tot As Double subtot = "0.00" Dim sql As String sql = "SELECT items.qty, products.descrip, products.price FROM items INNER JOIN products ON items.productid = WHERE (items.orderid = " & Request.QueryString("oid") & ")"Dim objConn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\AllStar.mdf;Integrated Security=True;User Instance=True") Dim cmdCustomers As New SqlCommand(sql, objConn)Dim dataReader As SqlDataReader objConn.Open() dataReader ...

how to format number to 4 decimal places
I have a decimal type number in my datagrid that I want to format to 4 decimal places. I tried <asp:BoundColumn ... FormatString="{0:n}" ..../> It give me only two decimal places: 0.28 How can I format my number to display as: 0.2833 (4 decimal places)? Check out this link: Met bet is: Console.WriteLine("Number formatting to 4 decimal places: " + theDecNumber.ToString("N4")); HighOnCodingWanna get high!  Try theDecNumber.ToString("###0.0000"); http:/...

Decimal places..
Hey everyone :) I'm having a problem formatting a number to two decimal places. Here's the code: Aspx page <% iFileSize = 9496296; %> <td align="RIGHT">                                <% = FormatNumber(iFileSize / 1048576)%> M</td>   C# Page public static string FormatNumber(double oNumValue)    {        double strResult = 0;     ...

Decimal Places
I've got report where the field I'm display is text, sometimes it will be numeric other times not. When it's numeric I'm rounding to apply decimal places. The problem comes in when I get a value like 5.004 and I want the report to round to one decimal place. It displays the number as just 5, not 5.0 If I try to use the general Format and apply something like '###.#' it doesn't work. It just diplays the ###.# for all fields. Any ideas on how to make the decimal point show even if it's zero? Thanks, Suzanne I make the format ###,##0.0 Th...

Web resources about - plz Help: Converting 4 decimal places to 1 decimal place -

Facebook Begins Converting Users To HTTPS
Are you willing to sacrifice a little bit of speed for a lot more safety? Facebook is asking that very question with its announcement that it ...

Facebook No Longer Converting Groups Into Pages
Back when Facebook first launched Facebook Pages, many businesses and brands who had built up substantial audiences in their Facebook Groups ...

Vert - simply converting for iPhone, iPad, and iPod touch on the iTunes App Store
Get Vert - simply converting on the App Store. See screenshots and ratings, and read customer reviews.

Converting SIM Card to Micro SIM Card - Flickr - Photo Sharing!
Place new Micro SIM into the iPhone SIM card tray

Ayaan Hirsi Ali on Converting Muslims to Christianity - YouTube
Complete video at: Ayaan Hirsi Ali explains her support of missionary ...

Converting dry air to water: solution to Broken Hill's water crisis gains support
A one-man crusade by a Broken Hill resident to solve the historic town's water crisis by introducing air to water converters is gaining support. ...

Click go fears of converting print files
Is there a way to convert a print queue item to a .RTF or .PDF file? I like to save or email them. - The Sydney Morning Herald

Sudanese woman ordered to hang under sharia law for converting to Christianity gives birth
Khartoum, Sudan: A Christian Sudanese woman sentenced to hang for apostasy has given birth in jail, a Western diplomat said on Tuesday.

Imams warn against radicalism to Aboriginal inmates converting to Islam
The prison system has enlisted the help of ASIO to crack down on radicalisation behind bars amid revelations that Aboriginals are converting ...

Converting the world's companies one by one - The Science Show - ABC Radio National (Australian Broadcasting ...
Image: Trucks carrying logs make their way up a road in Jambi, Indonesia. A vast area of the Sumatran forest, and orangutan habitat, is being ...

Resources last updated: 2/9/2016 11:19:37 PM