|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.ColumnName,
DataType = defindedDataTable.Columns.DataType,
Expression = defindedDataTable.Columns.Expression,
ColumnMapping = defindedDataTable.Columns.ColumnMapping
foreach (DataRow row in defindedDataTable.Rows)
DataRow newRow = dt.NewRow();
|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",
|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
a template that deletes the schema element
a template that converts integers to decimal notation
<xsl:template match="*[not(*)][translate(., '0123456789', '') = '']">
<xsl:value-of select="format-number(number(.), '0.00000')"/>
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]".
|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,
|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();
|How to convert varchar2 column containing decimal numbers to number|
You can try updating only those validates to be a numeric like,
set new_discount = CASE WHEN regexp_like(discount,
to_number(discount) ELSE -99999 END
|Convert GridView.DataSource with DateTime column to datatable|
Try this way
DataView dv=(DataView) from test in db.Tests
courseName = test.Course.Name,
onDate = test.OnDate,
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
|SQL Server - Convert decimal to string with padding - implied decimal|
Maybe the following sql code will be useful:
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)
You can try this here sqlfiddle.
Note: NUMBER is your field, and TEST is your TABLE.
|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
|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
|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.
|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)
<your existing query here>
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" & _
Using cn As New SqlConnection("c
|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();
|.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
Cast (LocationNameLocationName As varChar(...) As LocName
, LocX As XCoord
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
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
|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:
|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
Or you could do this all in one go with
CAST(NULL AS DECIMAL(18, 4)) AS new_col
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
|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
Convert each byte to a number, and then use itoa to get the ascii value.
|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 :)
|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(,)
|how to parse a decimal value from JSON response|
Use NSJSONReadingMutableLeaves instead of NSJSONReadingAllowFragments. The
proper documentation can be found at
Let me know if it helped you or not.
|Can not parse datatable ajax request|
data%5B%5D decodes to data. So MVC can't match data with yor data
You could try this:
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
|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
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.
|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
var prevVersion = Version.Parse("10.0.20");
var currentVersion = Version.Parse("10.0.30");
var result = prevVersion < currentVersion;
Console.WriteLine(result); // true
|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)?
|How to parse times that may or may not have decimal seconds in Python (2.7)?|
t = t.rsplit('.', 1)
Or just make sure to add a decimal:
if not '.' in t:
t += '.0'
This should do it.
|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
|trying to parse negative monetary amount from string into decimal|
Something is clearly not right here, I suspect that line is not what you
think it is. Are you sure that line == "-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 == "-5017.85" is true, could you please try
var sAmount = Decimal.Parse(
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.Replace(""", ""));
|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.
i = int(s, 16)
This answer explains it.
|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.
|How do i convert from ASCII to Decimal|
Something like this:
String bslstr = String.valueOf(bslval & 0xff);
This assumes, the value is actually in bslval. The & 0xff is there
to get positive results for byte values between (byte)0x80 and (byte)0xff.
|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(
|convert from decimal to HEX in python|
Use the hex() built-in:
hex_number = hex(decimal_number) # hex_number now contains your number as
return (len(hex_number) - 2) == 16
|Convert Exponential value to Decimal|
Use the Round function:
total = 99.99
pct = Round(100-total, 2)
|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;
|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 :
|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
|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()
|how to convert datatable to json in C#|
This code snippet from Convert Datatable to JSON String in C#, VB.NET
might help you.
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",
SqlDataAdapter da = new SqlDataAdapter(cmd);
|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
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.
I am assuming you want to round off the value to nearest integer
SET [2 37] =
CAST(CAST(FLOOR(CONVERT(decimal(10,5),(CAST([2 37] AS varchar(10))))) as
AS text )
WHERE [2 37] LIKE '%.%'
SET [2 37] = CAST(
CONVERT(decimal(10,5),(CAST([2 37] AS varchar(10))))) as VARCHAR(10))
AS text )
WHERE [2 37] LIKE '%.%'