type-conversion

How to convert varchar to decimal(38,2)?

妖精的绣舞 提交于 2021-02-11 17:14:50
问题 I have a problem converting from a varchar '000000113754' to decimal 1137.54 I'm comparing two expressions: 1. select STUFF('000000113754', LEN('000000113754') - 1, 0, '.') 2. select STUFF([dbo].fn_PrepareNumeric(('000000113754' + '-'), '+','-'), LEN('000000113754') - 1, 0, '.') The function fn_PrepareNumeric just checks for the sign and appends '-' in front if the sign is - . That's all. The problem is that the first expression gives me the correct varchar - 0000001137.54 , and the second

How to convert varchar to decimal(38,2)?

十年热恋 提交于 2021-02-11 17:14:29
问题 I have a problem converting from a varchar '000000113754' to decimal 1137.54 I'm comparing two expressions: 1. select STUFF('000000113754', LEN('000000113754') - 1, 0, '.') 2. select STUFF([dbo].fn_PrepareNumeric(('000000113754' + '-'), '+','-'), LEN('000000113754') - 1, 0, '.') The function fn_PrepareNumeric just checks for the sign and appends '-' in front if the sign is - . That's all. The problem is that the first expression gives me the correct varchar - 0000001137.54 , and the second

How to realize automatic type conversion for template methods?

别说谁变了你拦得住时间么 提交于 2021-02-11 15:18:03
问题 I am using self-written template methods to load and save settings from/into Qt's QSettings . QSettings receive/return data of type QVariant and QVariant has constructors taking basic types like int and double , but not std::string . My template method can therefore easily be used for int and double , but when using std::string I get compile error messages that there is no matching function call, because there is no known conversion from std::__cxx11::basic_string<char> to the types accepted

Ambiguous user defined conversions, when converting from X to Y. C# .Net

拜拜、爱过 提交于 2021-02-10 18:50:48
问题 I wanted to know the reason behind allowing to define redundant conversion implementations in different classes but displaying a failure while trying to consume them. public class Celsius { public Celsius(float temp) { Degrees = temp; } public float Degrees { get; } public static explicit operator Fahrenheit(Celsius c) { return new Fahrenheit((9.0f / 5.0f) * c.Degrees + 32); } public static explicit operator Celsius(Fahrenheit fahr) { return new Celsius((5.0f / 9.0f) * (fahr.Degrees - 32)); }

Ambiguous user defined conversions, when converting from X to Y. C# .Net

穿精又带淫゛_ 提交于 2021-02-10 18:50:44
问题 I wanted to know the reason behind allowing to define redundant conversion implementations in different classes but displaying a failure while trying to consume them. public class Celsius { public Celsius(float temp) { Degrees = temp; } public float Degrees { get; } public static explicit operator Fahrenheit(Celsius c) { return new Fahrenheit((9.0f / 5.0f) * c.Degrees + 32); } public static explicit operator Celsius(Fahrenheit fahr) { return new Celsius((5.0f / 9.0f) * (fahr.Degrees - 32)); }

How to convert a raw 64-byte binary to Hex or ASCII in C

北战南征 提交于 2021-02-10 16:17:49
问题 I´m using SHA512 in C to get an Hash-Value. I did it like this: #include <stdlib.h> #include <stdio.h> #include <openssl/sha.h> int main(int argc, char *argv[]){ unsigned char hash[SHA512_DIGEST_LENGTH]; char data[] = "data to hash"; //Test Data SHA512(data, sizeof(data) - 1, hash); //Kill termination character //Now there is the 64byte binary in hash I tried to convert it to hex by: long int binaryval, hexadecimalval = 0, i = 1, remainder; binaryval=(long int)hash; while (binaryval != 0) {

Python: endog has evaluated to an array with multiple columns

时光毁灭记忆、已成空白 提交于 2021-02-10 15:52:19
问题 I'm trying to run a Poisson model, like this: poisson_model_xg = smf.glm(formula="xG ~ home + team + opponent", data=xg_model_data, family=sm.families.Poisson()).fit() I'm getting the following error: ValueError: endog has evaluated to an array with multiple columns that has shape (760, 9). This occurs when the variable converted to endog is non-numeric (e.g., bool or str). But I can't figure out what does it mean, since all my dataframe is numeric: xg_model_data.apply(lambda s: pd.to_numeric

Python: endog has evaluated to an array with multiple columns

柔情痞子 提交于 2021-02-10 15:48:22
问题 I'm trying to run a Poisson model, like this: poisson_model_xg = smf.glm(formula="xG ~ home + team + opponent", data=xg_model_data, family=sm.families.Poisson()).fit() I'm getting the following error: ValueError: endog has evaluated to an array with multiple columns that has shape (760, 9). This occurs when the variable converted to endog is non-numeric (e.g., bool or str). But I can't figure out what does it mean, since all my dataframe is numeric: xg_model_data.apply(lambda s: pd.to_numeric

Yii2: How to convert data type value of a JSON PHP array?

≡放荡痞女 提交于 2021-02-10 15:29:12
问题 I am using Yii2 framework to create this JSON array: "data": [ { "id": 201, "name": "John", "age": "30" } ] The age is a string and I need it to be an integer , that is, without quotation marks. Like this: "data": [ { "id": 201, "name": "John", "age": 30 } ] This is the PHP function that create the JSON array: $persons['data'] = Persons::find() ->select([ 'id', 'name', 'age' ]) ->asArray() ->all(); 回答1: You can use JSON_NUMERIC_CHECK flag as second parameter of json_encode() or \yii\helpers

Powershell Convert String With ENV Variable

纵然是瞬间 提交于 2021-02-10 08:39:33
问题 I have the following code: $myVar = 'C:\Users\$env:USERNAME\Desktop' Test-Path "$myVar" The variable $myVar is needed with single quotes to display the actual variables used to the user. How can I then actually process the variable later into the actual path to use? Test-Path $myVar returns False , not seeing the users path "C:\Users\User\Desktop" 回答1: Found it! As the single quotes could not be changed in the original variable $myVar , the following worked to expand its variable later: