w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
select column from datatable and convert this to datatable again
This will create a new table, insert the single column, and populate with rows containing original data: DataTable dt = new DataTable(); DataColumn column = new DataColumn() { ColumnName = defindedDataTable.Columns[0].ColumnName, DataType = defindedDataTable.Columns[0].DataType, Expression = defindedDataTable.Columns[0].Expression, ColumnMapping = defindedDataTable.Columns[0].ColumnMapping }; dt.Columns.Add(column); foreach (DataRow row in defindedDataTable.Rows) { DataRow newRow = dt.NewRow(); newRow[defindedDataTable.Columns[0].ColumnName] = row[defindedDataTable.Columns[0].ColumnName]; dt.Rows.Add(newRow); }

Categories : C#

Convert or parse string to decimal
If your culture uses . as the decimal separator : double d = double.Parse("7.0000000000000007E-02"); Or try that way : decimal d = Decimal.Parse("7.0000000000000007E-02", System.Globalization.NumberStyles.Float);

Categories : C#

How to Dynamically parse xml using xslt to detect integers and convert that to decimal? I have schema also in the xml file I need that to be deleted
You want a stylesheet with: an identity template that copies elements by default <xsl:template match="*"> <xsl:copy><xsl:apply-templates/></xsl:copy> </xsl:template> a template that deletes the schema element <xsl:template match="*:schema"/> a template that converts integers to decimal notation <xsl:template match="*[not(*)][translate(., '0123456789', '') = '']"> <xsl:copy> <xsl:value-of select="format-number(number(.), '0.00000')"/> </xsl:copy> </xsl:template> All the above is XSLT 1.0. The third template could be made a bit nicer with XSLT 2.0: match="*[. castable as xs:integer]".

Categories : Xml

Decimal.Parse/Double.Parse Returns a Value without the Decimal Point
My strong suspicion is that you're running on a machine with a culture which doesn't use . as a decimal point. Specify the culture explicitly, e.g. to the invariant culture decimal margin1 = decimal.Parse(strProfitMargin, CultureInfo.InvariantCulture);

Categories : C#

How to Convert DataTable Column values from One Unit to another in C#?
You will need to keep the conversion data in some sort of container, for example to keep a matrix of values where each row will use for from unit and each column will for to unit (so if x==y the value will be 1 since converting from any unit to the same unit is multiplying it by one) After you have the matrix your code will look like: double value_to_convert = Double.Parse(strToConvert); return (value_to_convert* mat[from][to]).ToString();

Categories : C#

How to convert varchar2 column containing decimal numbers to number
You can try updating only those validates to be a numeric like, update table_name set new_discount = CASE WHEN regexp_like(discount, '^[+-]?([0-9]*.?[0-9]+|[0-9]+.?[0-9]*)([eE][+-]?[0-9]+)?$') THEN to_number(discount) ELSE -99999 END

Categories : SQL

Convert GridView.DataSource with DateTime column to datatable
Try this way DataView dv=(DataView) from test in db.Tests select new { testId= test.TestId, courseName = test.Course.Name, onDate = test.OnDate, lastRegisterDate = test.LastRegisterDate }; gridAllTests.DataSource = dv; DataTable dt = new DataTable(); DataSourceSelectArguments args = new DataSourceSelectArguments(); DataView dv = new DataView(); dv = (DataView)dv.Select(args);// This SqlDataSourceObject means your sql query return object ,like dataset or datavi

Categories : C#

SQL Server - Convert decimal to string with padding - implied decimal
Maybe the following sql code will be useful: SELECT CASE WHEN NUMBER < 100 THEN RIGHT('0000' + CAST(CAST(NUMBER AS INT) AS VARCHAR),4) ELSE RIGHT(SUBSTRING(CAST(NUMBER AS VARCHAR),1,CHARINDEX('.',CAST(NUMBER AS VARCHAR))-1),4) + LEFT(PARSENAME(NUMBER,1),1) END RESULT FROM TEST You can try this here sqlfiddle. Note: NUMBER is your field, and TEST is your TABLE.

Categories : SQL

Access adding column of type decimal(number with fieldsize decimal)
Your query looks fine. The decimal data type isn't supported in the default Jet 4.0 mdb file. You have to use the SQL Server compatibility syntax (ANSI 92) setting to use the decimal data type in the SQL Window. Click on the menu, Tools > Options. Click on the Tables/Query tab. Mark the check box for "This database" in the SQL Server compatibility syntax (ANSI 92) section. This mode will affect the entire db, including queries with wildcards, so you may want to try this on a copy of your db

Categories : SQL

Convert .net decimal type to tsql decimal(3,3)
Maximum value decimal(3,3) will allow is 0.999, so when you try to insert something larger than that exception will occur. try something like decimal(4,3)

Categories : C#

convert hex decimal numbers to decimal using python
If you have the hex bytes in readable form then use the decimal value as the key for the sort. hlist.sort(key=lambda x: int(x, 16)) If you have the raw hex bytes and they're all the same length then you don't need an explicit key, since bytestrings sort naturally. hlist.sort()

Categories : Python

adding results of query against datatable to a column in another datatable in visual basic
You can always nest that in another query: select *, datediff(ms, startDate, endTime) from ( <your existing query here> ) t And while I'm here, it seems you need a lesson in parameterized queries: Dim result As New DataTable Dim Sql As String = _ "SELECT *, datediff(ms, startDate, endTime) FROM (" & _ "SELECT ID, startDate, codeID, Param, " & _ "(select top 1 startDate from myTable " & _ "where ID= @ID and Param = mt.param and codeID = 82 and startDate >= @startDate and startDate >=mt.startDate " & _ "ORDER BY startDate) endTime " & _ " FROM myTable mt " & _ " WHERE ID = @ID AND startDate between @startDate AND @endDate AND codeID = 81" & _ ") t" Using cn As New SqlConnection("c

Categories : SQL

Insert DataTable rows to DataBaseTables using DataAdapter: leave out one column in DataTable
string qry = "select * from PurchaseProduct where 0 = 1"; sa = new SqlDataAdapter(qry, conn); dataSet = new DataSet(); sa.Fill(dataSet); dataSet.Tables[0].Columns.Add("dtcolnPurchaseProductProductName",typeof(string));

Categories : Misc

.NET Convert the contents of a DataTable to another DataTable with a different schema
I would normally do in select that "looks like" the destination table, but with data from the source table. You would apply the data conversions also as required. Select Cast (LocationNameLocationName As varChar(...) As LocName , LocX As XCoord , ... From SourceTable Hard to describe in a simple answer. what I've done in the past is issue an "empty" query like "Select * From sourcetable Where 1=0" which returns no rows but makes all the columns and their types available in the result set. You can cycle through the column ADO objects to get the type of each. You can then use that info to dynamically build a real SQL statement with the conversions. You still have a lot of logic to decide the conversion, but they all happen as you're building the statement, not as the table is being r

Categories : SQL

convert a hexadecimal into a decimal via string convert in java
Use the overloaded Integer.parseInt method that takes a second parameter for the radix: Integer.parseInt(str1, 16);

Categories : Java

Add Column to Temp Table - 'Invalid column name DECIMAL'
Don't use the AS. The correct syntax is ALTER TABLE #TEMP_TBL ADD new_col DECIMAL(18,4) /*Or whatever precision/scale */ Or you could do this all in one go with SELECT id, name, val, CAST(NULL AS DECIMAL(18, 4)) AS new_col INTO #TEMP_TBL FROM .... It thinks you are trying to add a computed column. CREATE TABLE #TEMP_TBL(X INT) /* Y is a computed column with same value as X*/ ALTER TABLE #TEMP_TBL ADD Y AS X

Categories : SQL

Parse Binary to Decimal
0000000 actually refers to the line number. It is not in the binary file, but is generated by your hex dump application. Your second line will contain 00000010, which represents Each line number will have 16 bytes max. Each line ends with a line feed, which is ascii 0xa. Every line will end with that. Convert each byte to a number, and then use itoa to get the ascii value.

Categories : C

Sorting on Column of datatable as alphabetically..or filter column
DataView dv = yourDataTable.DefaultView; dv.Sort = "Column2"; yourDataTable = dv.ToTable(); You don't need to add ASC, it's a default, unless you want DESC :) This code worked for me :)

Categories : C#

C# decimal.Parse() strange FormatException
I had a similar issue a few days back. This however was with my ModelBinding in a MVC project. I had to overwrite the class responsible for binding decimal values to model variables. Try to replace the full stop (.) with a comma(,)

Categories : C#

how to parse a decimal value from JSON response
Use NSJSONReadingMutableLeaves instead of NSJSONReadingAllowFragments. The proper documentation can be found at http://developer.apple.com/library/ios/#documentation/Foundation/Reference/NSJSONSerialization_Class/Reference/Reference.html Let me know if it helped you or not.

Categories : Iphone

Can not parse datatable ajax request
data%5B%5D decodes to data[]. So MVC can't match data[] with yor data parameter. You could try this: [Authorize, HttpPost] public ActionResult OnDeletePzeMaster( string action, string table, string id) { var data = this.Request.Form["data[]"]; } Or you could write a ModelBinder like this ASP.NET MVC - Custom model binder able to process arrays

Categories : Asp Net Mvc

XML deserialization crashes on decimal parse due to formatting
XML serializer uses a standardized Number and DateTime format, the standard is defined in the W3C schema datatype specification http://www.w3.org/TR/xmlschema-2/. Don't expect XmlSerializer to pay attention to the thread's CultureInfo, it intentionally uses a standardized format to ensure you can serialize/deserialize independent of the culture/locale.

Categories : C#

How to Parse a String with Multiple Decimal Points
The the string you're trying to parse looks like a verson, so try using the Version class. var prevVersion = Version.Parse("10.0.20"); var currentVersion = Version.Parse("10.0.30"); var result = prevVersion < currentVersion; Console.WriteLine(result); // true

Categories : C#

Decimal.TryParse Fails to parse integer value
This is weird, on my machine (.NET 4) even this works: Decimal.TryParse("asdf123&*", out someDecimal); By works I mean that TryParse returns false, no exception is thrown. Parse method may throw an exception - maybe you have some whitespace or string literally contains " (quotes)?

Categories : C#

How to parse times that may or may not have decimal seconds in Python (2.7)?
t = t.rsplit('.', 1)[0] time.strptime('%Y%m%d-%H:%M:%S.%f', t) Or just make sure to add a decimal: if not '.' in t: t += '.0' time.strptime('%Y%m%d-%H:%M:%S.%f', t) This should do it.

Categories : Python

Decimal. Parse string, postfixed by a minus sign
This is an accepted format for Decimal.Parse. The style option to the Parse method allows for leading and trailing signs. Read more: http://msdn.microsoft.com/en-us/library/91fwbcsb.aspx

Categories : C#

trying to parse negative monetary amount from string into decimal
Something is clearly not right here, I suspect that line[1] is not what you think it is. Are you sure that line[1] == "-5017.85" is true? Another possible scenario that you have a different culture setting that is preventing - from being parsed as the optional sign character or . as the decimal-point separator, but this is an unlikely scenarios. If you're sure that line[1] == "-5017.85" is true, could you please try var sAmount = Decimal.Parse( line[1], System.Globalization.CultureInfo.InvariantCulture ); and report back. I had debugged of course and the value is actually: ""-5017.85"" Well, in that case, I'd merely use String.Replace to replace the " characters with the empty string as in: var sAmount = Decimal.Parse(line[1].Replace(""", ""));

Categories : C#

convert hex value to decimal value
i = hex (sector_header) TypeError: hex() argument can't be converted to hex You are trying to convert it to a hex value. use int("ff", 16) i = int(s, 16) This answer explains it.

Categories : Python

how to convert fractional value into decimal value in php
You should select the SUM and COUNT separately instead of selecting the concatenated result. Then you'll be able to take ($row['sum'] / $row['count']) in your code or convert it as needed.

Categories : PHP

How do i convert from ASCII to Decimal
Something like this: String bslstr = String.valueOf(bslval[0] & 0xff); This assumes, the value is actually in bslval[0]. The & 0xff is there to get positive results for byte values between (byte)0x80 and (byte)0xff.

Categories : Java

C# convert string to decimal 4dp
Both Convert.ToDecimal and decimal.Parse do preserve trailing zeroes in the string (a System.Decimal can have at most 28-29 digits in total, so in most cases there's still room for all the trailing zeroes). And Math.Round(..., 4) preserves trailing zeroes up to the fourth place after the decimal period. Therefore the premise of the question is wrong. Your example does bring back what you want. In any case, consider specifying the overload that takes in an IFormatProvider as well, and give CultureInfo.InvariantCulture as argument. Then the conversion is independent of the local culture. If instead you want to handle strings like "145.83" and append trailing zeroes that were not in the string, use: string val = "145.83"; decimal sss = Math.Round( decimal.Parse(val, CultureInfo.Invar

Categories : C#

convert from decimal to HEX in python
Use the hex() built-in: def check_hex_length(decimal_number): hex_number = hex(decimal_number) # hex_number now contains your number as hex. return (len(hex_number) - 2) == 16

Categories : Python

Convert Exponential value to Decimal
Use the Round function: Dim total Dim pct total = 99.99 pct = Round(100-total, 2) MsgBox pct

Categories : Vbscript

Convert 3 Hex (byte) to Decimal
oct6 is being shifted 8 bits too far (32 instead of 24) decimal BaseFrequency = Convert.ToDecimal((oct9 | (oct8 << 8) | (oct7 << 16) | (oct6 << 24))) * 0.000005M;

Categories : C#

Joda-Time ISO8601 standard ISOPeriodFormat cannot parse decimal fraction
It looks like a limitation of jodatime. It has ISOPeriodFormat and PeriodFormatterBuilder for creating PeriodFormatters. But ISOPeriodFormat only supports a subset of the ISO8601 formats (none including fractional years) as per link in comments. PeriodFormatBuilder, although highly configurable, apparently will only deal with years as integers : http://joda-time.sourceforge.net/apidocs/org/joda/time/format/PeriodFormatterBuilder.html

Categories : Java

How to convert datatable to dictionary in ASP.NET/C#
The tricky thing here is the composite key (ClassID, ClassName). Once you identify that, it's easy to search this site for the solution. I'd recommend using tuples as pointed out here: Composite Key Dictionary

Categories : C#

Convert a DataTable to IList
Perhaps (works also if the table contains more rows): IList<Foo> data = table.AsEnumerable() .SelectMany(r => table.Columns.Cast<DataColumn>() .Select(col => new Foo { Name = col.ColumnName, Value = r.IsNull(col) ? null : r[col].ToString() })) .ToList();

Categories : Linq

how to convert datatable to json in C#
This code snippet from Convert Datatable to JSON String in C#, VB.NET might help you. It uses System.Web.Script.Serialization.JavaScriptSerializer to serialize the contents to JSON format: public string ConvertDataTabletoString() { DataTable dt = new DataTable(); using (SqlConnection con = new SqlConnection("Data Source=SureshDasari;Initial Catalog=master;Integrated Security=true")) { using (SqlCommand cmd = new SqlCommand("select title=City,lat=latitude,lng=longitude,description from LocationDetails", con)) { con.Open(); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(dt); System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();

Categories : Asp Net

How to get Hexadecimal input and convert it to decimal?
It seems to me like you are getting an error because of the initial case of the edText1.getText(). When the textfield is empty it still stores a value - "". "" is still a String and still has contents, yet it is not an integer. So, when you're doing Integer.parseInt() on it it's doing somthing like below: result.setText("" + Integer.parseInt("", 16)); "" is clearly not an integer or hexadecimal, yet it is still a String so it's having a problem formatting that, then throwing the error.

Categories : Android

Cast/Convert Text-Decimal
I am assuming you want to round off the value to nearest integer Rounding down UPDATE [dbo].[T01] SET [2 37] = CAST(CAST(FLOOR(CONVERT(decimal(10,5),(CAST([2 37] AS varchar(10))))) as VARCHAR(10)) AS text ) WHERE [2 37] LIKE '%.%' Rounding up UPDATE [dbo].[T01] SET [2 37] = CAST( CAST(CEILING( CONVERT(decimal(10,5),(CAST([2 37] AS varchar(10))))) as VARCHAR(10)) AS text ) WHERE [2 37] LIKE '%.%'

Categories : SQL



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.